Bug #77193 [Asn->Csd]: Infinite loop in preg_replace_callback
| From: | ab@php.net | Date: | Sat, 01 Dec 2018 09:29:36 +0000 |
| Subject: | Bug #77193 [Asn->Csd]: Infinite loop in preg_replace_callback | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-218235@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77193&edit=1
ID: 77193
Updated by: ab@php.net
Reported by: mlocati at gmail dot com
Summary: Infinite loop in preg_replace_callback
-Status: Assigned
+Status: Closed
Type: Bug
Package: PCRE related
PHP Version: 7.3.0RC6
Assigned To: ab
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ef1269d5c158afaf052e3d79591462e0f5372b1a
Log: Fixed bug #77193 Infinite loop in preg_replace_callback
Previous Comments:
------------------------------------------------------------------------
[2018-11-30 22:42:09] requinix@php.net
> @requinix your snippet doesn't repro, unfortunately.
That was to test if the problem was with the PCRE2 code in general or if it was specifically about
how ext/filter and FILTER_VALIDATE_REGEXP uses it.
------------------------------------------------------------------------
[2018-11-30 21:56:29] ab@php.net
@mlocati, excellent! I'll add it as a test.
@requinix your snippet doesn't repro, unfortunately.
Thanks.
------------------------------------------------------------------------
[2018-11-30 16:54:44] requinix@php.net
What happens with this?
<?php
$text = '{CCM:CID_2}';
echo '1';
preg_replace_callback(
'/([0-9]+)/i',
function ($matches) {
echo $matches[1];
preg_match('/^http$/i', '');
},
$text
);
echo '3';
------------------------------------------------------------------------
[2018-11-30 16:46:36] mlocati at gmail dot com
PS: I'm on Windows, so -1073741819 is the 0xC0000005 (STATUS_ACCESS_VIOLATION) system error
------------------------------------------------------------------------
[2018-11-30 16:41:16] mlocati at gmail dot com
It took me quite some time to keep removing stuff to get to a test script as simple as possible, and
here it is:
<?php
$text = '{CCM:CID_2}';
echo '1';
preg_replace_callback(
'/([0-9]+)/i',
function ($matches) {
echo $matches[1];
filter_var('http', FILTER_VALIDATE_REGEXP, ['options' =>
['regexp' => '/^http$/i']]);
},
$text
);
echo '3';
It should print '123', but it prints '1' and an infinite number of
'2'.
If you set $text to just a digit (eg '2'), just '12' is printed out, and PHP
quits with an error level -1073741819 (I'm using a 32-bit PHP).
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=77193
--
Edit this bug report at https://bugs.php.net/bug.php?id=77193&edit=1