Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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?

Replies are listed 'Best First'.
Re: regex bug in perl 5.8.7
by dmitri (Priest) on May 25, 2007 at 16:44 UTC
Re: regex bug in perl 5.8.7
by dave_the_m (Prior) on May 25, 2007 at 18:41 UTC
    Appears to be fixed in 5.9.4.


      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 TGI (Parson) 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, the Perl Home Pa +ge.

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.

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: regex bug in perl 5.8.7
by vrk (Chaplain) on May 25, 2007 at 18:22 UTC

    Confirmed, crashes here, too.

    This is perl, v5.8.8 built for i486-linux

    print "Just Another Perl Adept\n";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://617538]
Front-paged by naikonta
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-08-22 23:29 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (344 votes). Check out past polls.