#44764 [NEW]: preg_match returning empty array on certain string lengths

From: Date: Thu, 17 Apr 2008 18:14:17 +0000
Subject: #44764 [NEW]: preg_match returning empty array on certain string lengths
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-124329@lists.php.net to get a copy of this message
From: steemann at globalpark dot de Operating system: Linux rom 2.4.21-297-smp4G PHP version: 5.2.5 PHP Bug Type: *Regular Expressions Bug description: preg_match returning empty array on certain string lengths 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 bug report at http://bugs.php.net/?id=44764&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=44764&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=44764&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=44764&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=44764&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=44764&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=44764&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=44764&r=needscript Try newer version: http://bugs.php.net/fix.php?id=44764&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=44764&r=support Expected behavior: http://bugs.php.net/fix.php?id=44764&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=44764&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=44764&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=44764&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44764&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=44764&r=dst IIS Stability: http://bugs.php.net/fix.php?id=44764&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=44764&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=44764&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=44764&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=44764&r=mysqlcfg

« previous php.bugs (#124329) next »