Doc #25754 [Com]: preg_replace() and preg_replace_callback() crash with long matches
| From: | ferenczy at volny dot cz | Date: | Thu, 29 Sep 2011 13:00:17 +0000 |
| Subject: | Doc #25754 [Com]: preg_replace() and preg_replace_callback() crash with long matches | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-7282@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=25754&edit=1
ID: 25754
Comment by: ferenczy at volny dot cz
Reported by: ilya at lebedev dot net
Summary: preg_replace() and preg_replace_callback() crash
with long matches
Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: Win32
PHP Version: 4CVS-2003-10-04 (stable)
Block user comment: N
Private report: N
New Comment:
It's an Apache stack overflow issue. You probably need to increase Apache thread stack size,
which is set on Windows to 1 MB only by default (8 MB on Linux).
See this for more info: https://bugs.php.net/bug.php?id=47689 (last post
from me, [2011-09-29 12:35 UTC])
Previous Comments:
------------------------------------------------------------------------
[2004-02-22 15:19:17] nlopess@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
------------------------------------------------------------------------
[2003-10-28 18:16:55] coldrain at workingonit dot org
It seems the bug I reported (http://bugs.php.net/bug.php?id=26020) is a duplicate of this one. In
this (now bogus) bug report there is more info on a similar, yet different case.
It should be noted that the maximum amount of data between pairs of tags in this PCRE case is not a
constant as it differs between platforms, even with the same installed PHP versions. On a Debian
box, I was able to process about 11650 bytes between to matching div tags.
------------------------------------------------------------------------
[2003-10-04 22:04:17] sniper@php.net
From http://www.pcre.org/pcre.txt, LIMITATIONS:
"The maximum length of a subject string is the largest
positive number that an integer variable can hold. However,
PCRE uses recursion to handle subpatterns and indefinite
repetition. This means that the available stack space may
limit the size of a subject string that can be processed by
certain patterns."
This propably should be mentioned in our manual pages too.
(On Linux, the example script worked fine with 9344 chars between the tags, but 9345 crashed)
------------------------------------------------------------------------
[2003-10-04 19:56:54] ilya at lebedev dot net
Description:
------------
Regular expression from the J.Friedl's "Mastering regular expressions" book that
matches pair html tags:
#<tag([^>]*)>(((?!</?tag(?:[^>]*)>).)*)</tag>#si
When between <tag> and </tag> are more then 2100 bytes (symbols), Apache crashes.
Same happens without "s" modifier, if string has no "newline" codes.
Reproduce code:
---------------
===
preg_replace("#<tag([^>]*)>(((?!</?tag(?:[^>]*)>).)*)</tag>#si","","<tag>
2200 symbols</tag>");
===
or
===
function callback (&$m) { return "";};
preg_replace_callback
("#<tag([^>]*)>(((?!</?tag(?:[^>]*)>).)*)</tag>#si","callback","<tag>
2200 symbols </tag>");
===
Expected result:
----------------
Match blocks bigger then 2100 symbols long.
Actual result:
--------------
With more then 2100 sybmols between tags Apache crashes.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=25754&edit=1