php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33468 preg_match on long strings fails
Submitted: 2005-06-24 18:24 UTC Modified: 2005-09-20 15:51 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: mjsherman at chartermi dot net Assigned: andrei (profile)
Status: Not a bug Package: PCRE related
PHP Version: 5CVS, 4CVS (2005-08-09) OS: *
Private report: No CVE-ID: None
 [2005-06-24 18:24 UTC] mjsherman at chartermi dot net
Description:
------------
preg_match, if passed a long subject string, fails unexpectedly.

I have read through the PCRE limitations, and can't see that this is one of them.  I have tried increasing memory limit (to increase the stack) with the same results.

Cutoff and examples are below:

Reproduce code:
---------------
$subject = str_repeat('a',100);
$subject .= str_repeat('b', 4370);
$subject .= str_repeat('a', 100);
if (preg_match('/(.*).*?\1/',$subject)) {
  echo "OK\n";
}

Expected result:
----------------
"OK" to be printed after matching 100 "a"s.
If 4370 is changed to 4369, then "OK" is printed.

Actual result:
--------------
With 4370 'b's, nothing is printed (failed preg_match)
With 4369 'b's, "OK" is printed (worked).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-24 19:30 UTC] tony2001@php.net
Andrei, could you check it plz.
As far as I understand, this is something not related to PHP, but just another PCRE limitation.
 [2005-08-09 10:36 UTC] sniper@php.net
Happens also with the new PCRE 6.2 lib which was bundled in PHP CVS today.
 [2005-08-11 00:13 UTC] bugs dot php dot net at chsc dot dk
An even simpler testcase:

$data = str_repeat('a', 9999);
preg_match('/(?:[a])*/', $data, $reg);

Notice that the parenthesis is non-capturing, i.e. we don't even put a lot of elements in the $reg array.
 [2005-09-20 15:51 UTC] iliaa@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.

This is the limitation of PCRE library, which limits the size of certain elements to prevent massive memory usage. This is not a PHP limit and as such is not a PHP bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 21:01:31 2024 UTC