when disabling regex implicit check string we must reset anchored flag
authorYves Orton <demerphq@gmail.com>
Sat, 19 Jun 2010 11:41:10 +0000 (13:41 +0200)
committerYves Orton <demerphq@gmail.com>
Thu, 24 Jun 2010 16:51:40 +0000 (18:51 +0200)
It seems that if a regex check string is determined to be "not useful"
it is permananently disabled. However, it appears that when doing this
we dont necessarily reset any flags that are related to it.

Worse, the behaviour is not determinisitic, so it is quite possible that
a given program may experience this bug "randomly" based on what strings
it was matching. Thus it may be difficult to reproduce.

Resetting the RXc_ANCH_MBOL when we know that it is implicit
(PREGf_IMPLICIT) seems to fix /this/ particular example. But it wouldn't
surprise me to discover that other "random" bugs we encounter can be
traced back to this behaviour.

This fixes RT #75878 which is derived from ActiveState Bug #87173.

    http://bugs.activestate.com/show_bug.cgi?id=87173
    http://rt.perl.org/rt3/Ticket/Display.html?id=75878

regexec.c
t/re/pat.t

index 50807e4..ef55635 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -994,10 +994,15 @@ Perl_re_intuit_start(pTHX_ REGEXP * const rx, SV *sv, char *strpos,
            prog->float_substr = prog->float_utf8 = NULL;       /* clear */
            check = NULL;                       /* abort */
            s = strpos;
+           /* XXXX If the check string was an implicit check MBOL, then we need to unset the relevent flag
+                   see http://bugs.activestate.com/show_bug.cgi?id=87173 */
+           if (prog->intflags & PREGf_IMPLICIT)
+               prog->extflags &= ~RXf_ANCH_MBOL;
            /* XXXX This is a remnant of the old implementation.  It
                    looks wasteful, since now INTUIT can use many
                    other heuristics. */
            prog->extflags &= ~RXf_USE_INTUIT;
+           /* XXXX What other flags might need to be cleared in this branch? */
        }
        else
            s = strpos;
index 7b9594c..d7cf718 100644 (file)
@@ -23,7 +23,7 @@ BEGIN {
 }
 
 
-plan tests => 299;  # Update this when adding/deleting tests.
+plan tests => 350;  # Update this when adding/deleting tests.
 
 run_tests() unless caller;
 
@@ -993,6 +993,16 @@ sub run_tests {
         ok "\x{ff08}." =~ m/\N{FULLWIDTH LEFT PARENTHESIS}./ && $& eq "\x{ff08}.";
         ok "\x{ff08}." =~ m/[\N{FULLWIDTH LEFT PARENTHESIS}]./ && $& eq "\x{ff08}.";
     }
+    {
+        my $n= 50;
+        # this must be a high number and go from 0 to N, as the bug we are looking for doesnt
+        # seem to be predictable. Slight changes to the test make it fail earlier or later.
+        foreach my $i (0 .. $n)
+        {
+            my $str= "\n" x $i;
+            ok $str=~/.*\z/, "implict MBOL check string disable does not break things length=$i";
+        }
+    }
 
 } # End of sub run_tests