develooper Front page | perl.perl5.porters | Postings from January 2011

Re: [perl #80190] Length-caching bug in utf8::decode

Thread Previous | Thread Next
From:
Tony Cook
Date:
January 10, 2011 04:54
Subject:
Re: [perl #80190] Length-caching bug in utf8::decode
Message ID:
20110110125401.GA21621@mars.tony.develop-help.com
On Mon, Dec 06, 2010 at 04:50:52PM +1100, Tony Cook wrote:
> On Fri, Dec 03, 2010 at 07:22:34PM -0500, Eric Brine wrote:
> > On Fri, Dec 3, 2010 at 1:41 PM, Eric Brine <perlbug-followup@perl.org>wrote:
> > 
> > > # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=80190 >
> > > There's a length caching bug in utf8::decode.
> > >
> > 
> > I don't know how to invalidate the cache, but it should be done after
> > SvUTF8_on(sv) in Perl_sv_utf8_decode in sv.c.
> 
> Looks like:
> 
>    MAGIC *mg = NULL;
>    utf8_mg_len_cache_update(sv, &mg, -1);
> 
> except that it add the magic if it wasn't already there.  Maybe:
> 
>    MAGIC *mg = mg_find(sv, PERL_MAGIC_utf8);
>    if (mg)
>      utf8_mg_len_cache_update(sv, &mg, -1);
> 
> Looks like the pos() cache should also be updated/cleared.

Actually, looking at how this is all implemented, the solution could
be as simple as:

  SvSETMAGIC(sv);

since Perl_magic_setutf8() clears the saved length and pos cache.

Putting that in XS_utf8_decode() in universal.c would be safest in
terms of the least side-effects on other code, but may leave other
code that calls sv_utf8_decode() with the same problem.

Tony

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About