Bug #60664 [Com]: mb_ereg leads to script executing timeout
| From: | ju1ius at laposte dot net | Date: | Sat, 30 Jul 2016 12:45:41 +0000 |
| Subject: | Bug #60664 [Com]: mb_ereg leads to script executing timeout | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-202724@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60664&edit=1
ID: 60664
Comment by: ju1ius at laposte dot net
Reported by: tyz at open dot by
Summary: mb_ereg leads to script executing timeout
Status: Open
Type: Bug
Package: mbstring related
Operating System: Debian
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
This is not a bug.
You should fix your regexp first.
The pattern you're using is a typical case of catastrophic backtracking.
http://www.regular-expressions.info/catastrophic.html
You can test it here: https://regex101.com/ and see that any
regexp engine will have a really hard time matching this pattern.
Previous Comments:
------------------------------------------------------------------------
[2016-07-30 11:34:00] cmb@php.net
Might be related to bug #53099.
------------------------------------------------------------------------
[2012-01-05 12:57:15] tyz at open dot by
Description:
------------
I tried this with php 5.3.8 and 5.3.2 with the same results.
Test script:
---------------
<?php
$content = '<div class="private-sales-index">
<div class="box">
<div class="content">
<h1>Welcome to our Exclusive Online Store</h1>
<p>If you are a registered member, please <a href="{{store
url="customer/account/login"}}">log in here</a>.</p>
<p class="description">Magento is the leading hub for exclusive specialty items for
all your home, apparel and entertainment needs!</p>
</div>
</div>
</div>';
$content = mbereg_replace("\r\n", ' ', $content);
$content = mbereg_replace("\n", ' ', $content);
var_dump($content);
var_dump(mb_ereg('(.*?\s){100}', $content, $_m));
var_dump($_m);
Expected result:
----------------
$content should be truncated to string that contains ~100 words.
Actual result:
--------------
Script executing hangs.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60664&edit=1