|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-08-06 15:22 UTC] johnston dot joshua at gmail dot com
Description:
------------
When running a preg_match with a capturing subpattern against large input, php crashes with a Segmentation Fault
I tested this on OS X and OpenSuSE, same result
OS X:~$ php -v
PHP 5.2.6 (cli) (built: Jul 15 2008 12:18:21)
OpenSuSE:~# php -v
PHP 4.4.7 (cgi) (built: May 12 2008 10:19:51)
Reproduce code:
---------------
<?php
preg_match("/http:\/\/(.)+\.ru/i", str_repeat("http://google.ru", 2000));
?>
Expected result:
----------------
PHP should handle the error or something other than letting PCRE crash php
Actual result:
--------------
jjohnston:~$ php -r 'preg_match("/http:\/\/(.)+\.ru/i", str_repeat("http://google.ru", 2000));'
Segmentation fault
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 03:00:01 2025 UTC |
I seen that PCRE has a NO_RECURSE flag to avoid the recursion in match() (described in pcre_exec.c). Defining NO_RECURSE at compile time avoids this problem :) diff -u -r1.38.2.3.2.10.2.3 config0.m4 --- ext/pcre/config0.m4 2 Jun 2008 14:12:20 -0000 1.38.2.3.2.10.2.3 +++ ext/pcre/config0.m4 7 Aug 2008 11:25:39 -0000 @@ -59,7 +59,7 @@ pcrelib/pcre_ord2utf8.c pcrelib/pcre_refcount.c pcrelib/pcre_study.c \ pcrelib/pcre_tables.c pcrelib/pcre_try_flipped.c pcrelib/pcre_valid_utf8.c \ pcrelib/pcre_version.c pcrelib/pcre_xclass.c" - PHP_NEW_EXTENSION(pcre, $pcrelib_sources php_pcre.c, no,,- + PHP_NEW_EXTENSION(pcre, $pcrelib_sources php_pcre.c, no,,- PHP_ADD_BUILD_DIR($ext_builddir/pcrelib) PHP_INSTALL_HEADERS([ext/pcre], [php_pcre.h pcrelib/]) AC_DEFINE(HAVE_BUNDLED_PCRE, 1, [ ])Just for my own personal knowledge, is it the capturing pattern the part that causes the recursion? If I remove the () part of the pattern I can keep adding 0's to the below code I can trigger a php memory error but no seg fault. jjohnston:~$ php -r 'preg_match("/http:\/\/.+\.ru/i", str_repeat("http://google.ru", 2000000));