#1 2012-01-14 18:28:56

debugger
Member
Registered: 2007-03-17
Posts: 44

[Patch] Problem with decoding arrays.

Hi Tian,

Look at GCPluginsBase.pm:

Code:

    sub convertCharset
    {
        my ($self, $value) = @_;

        my $result = $value;
        if (ref($value) eq 'ARRAY')
        {
            foreach my $line(@{$value})
            {
                my $i = 0;
                map {$_ = decode($self->getCharset, $_)} @{$line};
            }
        }
        else
        {
            eval {
                $result = decode($self->getCharset, $result);
            };
        }
        return $result;
    }

Note, that the second call to decode is enclosed into eval, but the first is not. This is the problem. decode may die if input octet sequence is incorrect, and die. I think it is the reson for eval. But the first decode call is not protected.

Please consider the fix:

Code:

    sub convertCharset
    {
        my ($self, $value) = @_;

        my $result = $value;
        my $charset = $self->getCharset();
        if (ref($value) eq 'ARRAY')
        {
            foreach my $line(@{$value})
            {
                foreach my $item(@$line)
                {
                    if (not utf8::is_utf8($item))
                    {
                        eval
                        {
                            $item = decode($charset, $item);
                        }
                    }
                }
            }
        }
        else
        {
            if (not utf8::is_utf8($result))
            {
                eval
                {
                    $result = decode($charset, $result);
                };
            }
        }
        return $result;
    }

BTW, this file in SVN does not follow your coding style: it has some tabs.

I attached the patch (based on untabbed version).


Attachments:
Attachment Icon GCPluginsBase.pm.patch, Size: 1,165 bytes, Downloads: 626

Offline

 

#2 2012-01-26 04:58:34

Garion
Member
Registered: 2010-07-27
Posts: 42

Re: [Patch] Problem with decoding arrays.

Hey!

Would you please take some time to describe what the .... for what is this? It would be nice to know, cause not every GCstar User has knowledge with Pearl or some kind of programming language. And the few words you wrote are not really helping me out. For instance, I don't even know if I have the problem you try to fix with this or not. Do I need this patch or not....I don't know.

Offline

 

#3 2012-01-26 17:56:26

debugger
Member
Registered: 2007-03-17
Posts: 44

Re: [Patch] Problem with decoding arrays.

There is a problem in gcstar: If plugin dies, gcstar does not show any error message but silently hangs (stops responding).

I faced this problem when I was working on my plugin. This fix does not solve the problem in general but avoids dying in some cases. A plugin may assume text is in some non-UTF-8 encoding and try to decode it, but text is actually is in UTF-8. `decode' function dies in such a case, causing gcstar hanging.

If you are not programmer and gcstar or gcstar's plugin developer, I guess you should wait official gcstar release and do not worry about this patch.

Offline

 

#4 2012-01-27 04:37:26

Garion
Member
Registered: 2010-07-27
Posts: 42

Re: [Patch] Problem with decoding arrays.

Ah, great. Your description is quite good, I get it. wink
Ok, so now I'm sure I don't need this plugin. I even don't use any plugin at the moment....except for my advanced shelf.html file, to export my collection into html...but this I changed by myself and it works great. wink

Thank you for your time and your kindness to explain yourself.

Offline

 



Should you have a problem using GCstar, you can open a bug report or request some support on GCstar forums.