Edit report at http://bugs.php.net/bug.php?id=54614&edit=1

 ID:                 54614
 User updated by:    php at richardneill dot org
 Reported by:        php at richardneill dot org
 Summary:            Trivial RE failure:  /([^b]*a*)*$/
-Status:             Feedback
+Status:             Open
 Type:               Bug
 Package:            *Regular Expressions
 Operating System:   Linux
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

Sorry, my bad (sort of). 



There is a genuine bug that affected longer regexps even with
backtrack.limit set

to 32M, which I saw on 5.3.2, but is now solved on 5.3.6.



Unfortunately, the test-case which I simplified for the bug-report
didn't

remember to set backtrack.limit (I thought I'd done it in php.ini, but
had

actually done it explicitly with ini.set in my original script). So the
test

case:

 - works for backtrack.limit = 1M  (on both 5.3.2 and 5.3.6)

 - fails for the default 100k   on both. 



Either way, it's still something that, imho, should work on a default
install.



May I make a few suggestions:



 * backtrack.limit should be raised by default, to at least 10M.

 * backtrack.limit should default to 100M for the CLI version of PHP.

 

 * validating bug reports is painful, partly because I had to spend some
extra

time tracking down the latest version of PHP and building it. This is
error-

prone. How about providing a sandboxed VM on bugs.php.net where we can
paste our

own code to check it? This would make it far easier to file correct bug
reports.

(it would take the reporter 3 minutes, rather than an hour).


Previous Comments:
------------------------------------------------------------------------
[2011-04-27 21:54:07] ras...@php.net

With pcre.backtrack_limit = 1000000 this works fine for me on 5.3.6. Are
you sure 

you increased the limit in the right place?

------------------------------------------------------------------------
[2011-04-27 21:15:34] php at richardneill dot org

A slightly simpler test case is:

  $contents =  "aaaaaaaab";

  $search = '/(a*a*)*$/';

------------------------------------------------------------------------
[2011-04-27 18:43:02] php at richardneill dot org

Description:
------------
If I search in the string :   'aaaaaaaab'

with the RE:   '/([^b]*a*)*$/'



then preg_replace fails with a backtrack-limit error. (error 2)

I have backtrack.limit configured to 32MB, so something is very wrong.



The example fails on several different PHP versions, CPU architectures
and Linux

Distros.  However, using Perl for the same RE works fine.

Test script:
---------------
$contents =  "aaaaaaaab";

$search = '/([^b]*a*)*$/';

$result = preg_replace($search,"x",$contents);

if ($result === NULL){

        echo "preg failed, error is ".preg_last_error()."\n";

}else{

        echo "success\n";

}

Expected result:
----------------
preg_replace shouldn't fail.

Actual result:
--------------
preg_replace returns NULL, and preg_last_error returns 2.


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54614&edit=1

Reply via email to