#44764 [Opn->Bgs]: preg_match returning empty array on certain string lengths
| From: | felipe@php.net | Date: | Thu, 17 Apr 2008 18:36:04 +0000 |
| Subject: | #44764 [Opn->Bgs]: preg_match returning empty array on certain string lengths | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-124333@lists.php.net to get a copy of this message | ||
ID: 44764
Updated by: felipe@php.net
Reported By: steemann at globalpark dot de
-Status: Open
+Status: Bogus
-Bug Type: *Regular Expressions
+Bug Type: PCRE related
Operating System: Linux rom 2.4.21-297-smp4G
PHP Version: 5.2.5
New Comment:
This is expected. The reason can be known using preg_last_error(), that
in the case returns 2. (2 = PREG_BACKTRACK_LIMIT_ERROR)
http://docs.php.net/manual/en/pcre.configuration.php#ini.pcre.backtrack-limit
Previous Comments:
------------------------------------------------------------------------
[2008-04-17 18:14:17] steemann at globalpark dot de
Description:
------------
When passing somewhat long strings to the first two parameters of
preg_match, the function result reproducibly changes to an empty
array if the one the strings gets too long.
The reproduce code works on PHP 5.1.4 CLI, but not on PHP 5.2.4 and
PHP 5.2.5 CLI.
When changing the string length of 1536 into 1535, the code also
works fine in PHP 5.2.x.
This affects the seconds parameter of preg_match.
If the 1536 in the reproduce code is reduced to 1535, the code will
work again. But if then the number of iterations in the for loop is
changed from 64 to 65 iterations, the code will misbehave again
(returning the empty array).
Seems to be some length overflow somewhere.
Reproduce code:
---------------
$parts=array();
for ($i=1;$i<=64;$i++)
{
$parts[]="#".$i."#";
}
preg_match("/^(.*)(".implode("|",$parts).")/",$parts[0].str_repeat("
",1536),$matches);
var_dump($matches);
Expected result:
----------------
array(3) {
[0]=>
string(3) "#1#"
[1]=>
string(0) ""
[2]=>
string(3) "#1#"
}
Actual result:
--------------
array(0) {
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44764&edit=1