develooper Front page | perl.perl5.porters | Postings from August 2008

Re: Wrong RE match in 5.10.0

Thread Previous | Thread Next
From:
Abigail
Date:
August 23, 2008 07:18
Subject:
Re: Wrong RE match in 5.10.0
Message ID:
20080823141843.GG5626@almanda
On Sat, Aug 23, 2008 at 04:06:54PM +0200, Bram wrote:
> Citeren Gisle Aas <gisle@activestate.com>:
>
>> In the Data::Dump module I had the following (stupid) regular
>> expression that ends up dumping core in 5.8 when the RE engine blows
>> the stack.  I'm fine with that, but what caught my eye was that 5.10.0
>> which avoids the segfault simply return the wrong match.  I think it
>> would have been better for it to raise an exception if it refuse to
>> loop longer than to return the wrong result.
>>
>> --Gisle
>>
>>
>> #!perl
>>
>> for (1, 10, 100) {
>>     $str = "x" x ($_ * 1024);
>>     if ($str =~ /^(.{1,5}?)(\1*)\z/s) {
>>         print "$1 ", length($2), "\n";
>>     }
>>     else {
>>         print "no match\n";
>>     }
>> }
>>
>> __END__
>>
>>
>> With 5.8 this prints:
>>
>> x 1023
>> x 10239
>> Segmentation fault
>>
>> With 5.10 this prints:
>>
>> x 1023
>> x 10239
>> xxxx 102396
>
>
> Reducded the example a bit more to make it more obvious (I was initially 
> confused by what you were saying):
>
> #!perl
>
> $str = "x" x (1024 * 100);
> if ($str =~ /^(.)(\1*)\z/) {
>   print "$1 ", length($2), "\n";
> }
> else {
>   print "no match\n";
> }
> __END__
>
> perl-blead prints 'no match' which is unexpected since logically  
> speaking the regex matches the input.


But if you turn on warnings, it's less unexpected, as Perl does warn:

    Complex regular subexpression recursion limit (32766) exceeded



Abigail

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