|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-02-12 22:12 UTC] 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 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 20:00:01 2025 UTC |
>Your pattern could be: /(@@ -[\d,]+ \+[\d,]+ @@\s)(?1)+/ Yes, it seems as workaround (for my current work I apply other workaraund too). It has not similar stack problems? Wuote from info by you link: Unfortunately, the effect of running out of stack is often SIGSEGV, though sometimes a more explicit error message is given. You can nor- mally increase the limit on stack size by code such as this: struct rlimit rlim; getrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = 100*1024*1024; setrlimit(RLIMIT_STACK, &rlim); So, main question is - may you correctly handle this problem at all (throw/catch exceptions, fire errors, warnings etc.)?? For example, code such: echo preg_replace('/(@@ -[\d,]+ \+[\d,]+ @@\s){2,643}/s', '-some data-', $text); generate warning: PHP Warning: preg_replace(): Compilation failed: regular expression is too large at offset 33 in /home/pasha/pcre-php-bug/pcre_bug.php on line 14 and all ok - I can correctly handle this situation on my script. In any case, on production server segmentation fault depended from incoming data is very-very bad idea.