Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

regex bug in perl 5.8.7

by imp (Priest)
on May 25, 2007 at 16:38 UTC ( #617538=perlquestion: print w/ replies, xml ) Need Help??
imp has asked for the wisdom of the Perl Monks concerning the following question:

I was revisiting Negating Regexes: Tips, Tools, And Tricks Of The Trade and caused perl to segfault with one of the patterns I tried. I reduced the pattern to he simplest form that still causes a problem. Tested with:
This is perl, v5.8.7 built for i486-linux-gnu-thread-multi Characteristics of this binary (from libperl): Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT

This works:

"1" =~ qr[(??{/^1/})]
This segfaults
"<" =~ qr[(??{/^</})]
Segfault re=debug output:
Freeing REx: `","' Compiling REx `(??{/^</})' size 4 Got 36 bytes for offset annotations. Compiling REx `^<' size 4 Got 36 bytes for offset annotations. first at 2 1: BOL(2) 2: EXACT <<>(4) 4: END(0) anchored `<' at 0 (checking anchored) anchored(BOL) minlen 1 Offsets: [4] 1[1] 2[1] 0[0] 3[0] first at 1 1: LOGICAL[2](2) 2: EVAL(4) 4: END(0) minlen 0 with eval Offsets: [4] 10[0] 10[0] 0[0] 11[0] Matching REx `(??{/^</})' against `<' Setting an EVAL scope, savestack=15 0 <> <<> | 1: LOGICAL[2] 0 <> <<> | 2: EVAL re_eval 0x8153fe8 Guessing start of match, REx `^<' against `<'... Guessed: match at offset 0 Matching REx `^<' against `<' Setting an EVAL scope, savestack=15 0 <> <<> | 1: BOL 0 <> <<> | 2: EXACT <<> 1 <<> <> | 4: END Match successful! Compiling REx `1' size 3 Got 28 bytes for offset annotations. first at 1 1: EXACT <1>(3) 3: END(0) anchored `1' at 0 (checking anchored isall) minlen 1 Offsets: [3] 1[1] 0[0] 2[0] Entering embedded `1' Setting an EVAL scope, savestack=21 0 <> <<> | 1: EXACT <1> failed... Freeing REx: `"1"' failed... Setting an EVAL scope, savestack=24 1 <<> <> |50339: LOGICAL[2] 1 <<> <> |50340: EVAL
Is this fixed in later perls?

Comment on regex bug in perl 5.8.7
Select or Download Code
Re: regex bug in perl 5.8.7
by dmitri (Curate) on May 25, 2007 at 16:44 UTC
Re: regex bug in perl 5.8.7
by TGI (Vicar) on May 25, 2007 at 16:58 UTC
    This example crashes for me with ActivePerl build 819, which is Perl 5.8.8


    TGI says moo

Re: regex bug in perl 5.8.7
by Skeeve (Vicar) on May 25, 2007 at 17:18 UTC
    Me too on PPC Mac
    skeeve@Skeeves-PowerBook:~ $ perl -e '"<" =~ qr[(??{/^</})]' Bus error skeeve@Skeeves-PowerBook:~ $ perl -v This is perl, v5.8.6 built for darwin-thread-multi-2level (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
Re: regex bug in perl 5.8.7
by w-ber (Hermit) on May 25, 2007 at 18:22 UTC

    Confirmed, crashes here, too.

    This is perl, v5.8.8 built for i486-linux
    Compile-time options: PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO

    --
    print "Just Another Perl Adept\n";

Re: regex bug in perl 5.8.7
by dave_the_m (Parson) on May 25, 2007 at 18:41 UTC
    Appears to be fixed in 5.9.4.

    Dave.

      Damn, I was looking forward to submitting a bug report :-/
        IIRC, demerphq has rewritten a substantial portion of the the regex system. If there are any bugs in it, they're likely new and different ones instead of the ones in earlier perls.


        Christopher E. Stith
Re: regex bug in perl 5.8.7
by diotalevi (Canon) on May 25, 2007 at 23:22 UTC

    You need a re-entrant regexp engine to do what you tried. I don't think even the latest bleads are. Also, your pattern isn't terribly meaningful. Are you *sure* you meant to use the return value of a boolean regexp as another regexp pattern to compile and apply?

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      The pattern isn't meant to be meaningful. The regex I listed was already reduced to the simplest case I could find that still caused a segfault. The original form was much different.

        In the future, you might want to use the (?{...}) form instead since that has no implications for compiling and interpolating another regexp.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://617538]
Front-paged by naikonta
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-09-16 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls