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

Re: Wrong RE match in 5.10.0

Thread Previous | Thread Next
From:
Bram
Date:
August 23, 2008 07:07
Subject:
Re: Wrong RE match in 5.10.0
Message ID:
20080823160654.52tqgl988wgww0k0@horde.wizbit.be
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.
perl-5.8.8 exists with a Segmentation fault.

The behaviour changed with Change 27598:
http://public.activestate.com/cgi-bin/perlbrowse/p/27598
Change 27598 by davem@davem-cyril on 2006/03/24 23:05:11

	make S_regmatch() iterative rather than recursive.
	Goodbye stack-bustng regexes!







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