http://qs321.pair.com?node_id=617538

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 (Monsignor) 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 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 (Parson) 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 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
    Compile-time options: PERL_MALLOC_WRAP USE_LARGE_FILES USE_PERLIO

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