develooper Front page | perl.perl5.porters | Postings from November 2010

Re: "perl: utf8.c:1997: Perl_swash_fetch: Assertion `klen <= sizeof(PL_last_swash_key)'failed." [5.12.1]

Thread Previous | Thread Next
From:
Reverend Chip
Date:
November 26, 2010 02:20
Subject:
Re: "perl: utf8.c:1997: Perl_swash_fetch: Assertion `klen <= sizeof(PL_last_swash_key)'failed." [5.12.1]
Message ID:
4CEF89F8.3010905@gmail.com
On 11/26/2010 1:23 AM, Nicholas Clark wrote:
> On Thu, Nov 25, 2010 at 07:47:39PM -0800, Chip Salzenberg wrote:
>> I've uncovered the string that's causing this problem.  When the
>> attached string has the utf8 bit enabled and a regex is applied, Perl
>> dies with the above exception.  Fortunately, utf8::valid() returns
>> false, so I have an easy way of avoiding this particular crash.  But
>> it's still a Perl bug that should be fixed - assertion failures should
>> not result from applying a regex, even to an invalid utf8 string.
> It's not clear that *that* is the perl bug.
> At what point is perl allowed to start trusting its internal data structures?
>
> Isn't the bug that perl let someone create an invalid data structure?

That's an internally consistent position (no pun intended).  But does
the utf8 flag truly count as internal if manipulating it is both easy
and well-documented for users?

In any case, it's a fair cop that Encode::Guess has a bug in that it led
the application down the road to ruin.

As a separate matter, perhaps we can at least agree that assert() is an
unfriendly thing for Perl to do in this case; I needed to run my program
with -Dt just to discover which line of Perl code triggered the
failure.  Perhaps croak() would be a better way to react to invalid
strings, even if the bug [as I would describe it] can't be fixed.


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