php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51741 preg_match returns zero if it hits backtracking limit
Submitted: 2010-05-04 20:32 UTC Modified: 2010-05-12 11:35 UTC
From: jordi dot salvat dot i dot alabart at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3SVN-2010-05-04 (SVN) OS: Ubuntu
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jordi dot salvat dot i dot alabart at gmail dot com
New email:
PHP Version: OS:

 

 [2010-05-04 20:32 UTC] jordi dot salvat dot i dot alabart at gmail dot com
Description:
------------
According to the documentation, pcre_match should return FALSE on error:

From http://docs.php.net/manual/en/function.preg-match.php :
<<
Return Values

preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject. preg_match() returns FALSE if an error occurred.
>>

Instead, it returns 0 (integer zero) -- see Felipe's comment on http://bugs.php.net/bug.php?id=51663&edit=2 for a check.

Note that pcretest does report an error in this same case:
$ pcretest
PCRE version 7.8 2008-09-05

  re> /(.+)+:/
data> \q10a:bbb
Error -8
data> 


Test script:
---------------
<?  
ini_set('pcre.backtrack_limit', 10);
print_r( preg_match('/(.+)+:/','a:bbb') === FALSE ? 'pass' : 'fail' );


Expected result:
----------------
pass

Actual result:
--------------
fail

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-12 09:52 UTC] mike@php.net
-Status: Open +Status: Bogus
 [2010-05-12 09:52 UTC] mike@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

> Note that pcretest does report an error in this same case

As can be queried with preg_last_error().
 [2010-05-12 11:15 UTC] jordi dot salvat dot i dot alabart at gmail dot com
So this is a documentation error.

I've tried to add a comment to http://docs.php.net/manual/en/function.preg-match.php, but I got this:

<<
Warning: include(/home/local/Web/sites/docs.php.net/manual/include/spam-func.php) [function.include]: failed to open stream: No such file or directory in /home/local/Web/sites/docs.php.net/manual/add-note.php on line 9

Warning: include() [function.include]: Failed opening '/home/local/Web/sites/docs.php.net/manual/include/spam-func.php' for inclusion (include_path='.:/local/php/lib/php') in /home/local/Web/sites/docs.php.net/manual/add-note.php on line 9

Fatal error: Call to undefined function kill_spammer() in /home/local/Web/sites/docs.php.net/manual/add-note.php on line 10
>>

I should have stuck to Java.
 [2010-05-12 11:35 UTC] bjori@php.net
docs.php.net is a development mirror, not an official mirror.
See http://php.net/mirrors

That bug has however been fixed, thanks for the report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC