ID: 47376
Updated by: felipe@php.net
Reported By: pahan at hubbitus dot spb dot su
Status: Bogus
Bug Type: PCRE related
Operating System: Linux
PHP Version: 5.3.0beta1
New Comment:
It's a known PCRE issue, and is documented:
http://www.manpagez.com/man/3/pcrestack/
Previous Comments:
------------------------------------------------------------------------
[2009-02-13 10:01:29] felipe@php.net
Your pattern could be: /(@@ -[\d,]+ \+[\d,]+ @@\s)(?1)+/
------------------------------------------------------------------------
[2009-02-13 09:01:51] pahan at hubbitus dot spb dot su
Thank you for the links it was pretty usefully.
I'm read information on it. Very strange read PHP documentation like:
====QUOTE:http://ru.php.net/manual/en/pcre.configuration.php====
pcre.recursion_limit integer
PCRE's recursion limit. Please note that if you set this value to a
*high number you may consume all the available process stack and
eventually crash PHP* (due to reaching the stack size limit imposed by
the Operating System).
====/QUOTE====
Really you can't provide any runtime check and provide standard way to
handle errors (or warnings)???
So, this low level limitation may be in pcre, but crash of PHP is PHP
BUG in any case!
And, If you a interesting, I'm make more investigation on this theme:
On default OS limit:
$ ulimit -s
10240
example script behaves as:
//ini_set('pcre.recursion_limit', 9939);//Segmentation fault
//ini_set('pcre.recursion_limit', 9938);//Work
So, If I increase stack size on my system:
$ ulimit -s 65536
all work fine, as expected!!!
------------------------------------------------------------------------
[2009-02-13 00:53:14] felipe@php.net
It isn't a PHP bug.
See bug#33468, bug#39387.
Thanks.
------------------------------------------------------------------------
[2009-02-12 22:51:08] pahan at hubbitus dot spb dot su
Sorry, sorry. Off course line "$text = file();" in reproduce code
unnecessary. Please remove it.
------------------------------------------------------------------------
[2009-02-12 22:12:28] pahan at hubbitus dot spb dot su
Description:
------------
On text, where search pattern repeated many times (>643 times by test)
php segfaulted (Core dump you may download here:
http://ru.bir.ru/_temp/php-pcre-bug/core.8729
) on preg_replace.
So, if we reduce length of test text (
http://ru.bir.ru/_temp/php-pcre-bug/pcre_bug.text
) on 1 line, or just
limit repetition on 1 - it is worked.
All Zend-modules was disabled.
Reproduce code:
---------------
<?
$text = file_get_contents('pcre_bug.text');
echo preg_replace('/(@@ -[\d,]+ \+[\d,]+ @@\s){2,}/s', '-some data-',
$text); //Segmentation fault
$text = file();
# Interesting:
#echo preg_replace('/(@@ -[\d,]+ \+[\d,]+ @@\s){2,642}/s', '-some
data-', $text); //Work, but result it is not same as needed.
#echo preg_replace('/(@@ -[\d,]+ \+[\d,]+ @@\s){2,643}/s', '-some
data-', $text); //PHP Warning: preg_replace(): Compilation failed:
regular expression is too large at offset 33
?>
Expected result:
----------------
Work as when text is less.
Actual result:
--------------
Segmentation fault
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47376&edit=1