|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60664 mb_ereg leads to script executing timeout
Submitted: 2012-01-05 12:57 UTC Modified: 2016-08-20 15:17 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: tyz at open dot by Assigned: cmb (profile)
Status: Not a bug Package: mbstring related
PHP Version: 5.3.8 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tyz at open dot by
New email:
PHP Version: OS:


 [2012-01-05 12:57 UTC] tyz at open dot by
I tried this with php 5.3.8 and 5.3.2 with the same results.

Test script:
$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>

$content = mbereg_replace("\r\n", ' ', $content);
$content = mbereg_replace("\n", ' ', $content);
var_dump(mb_ereg('(.*?\s){100}', $content, $_m));

Expected result:
$content should be truncated to string that contains ~100 words.

Actual result:
Script executing hangs.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-30 11:34 UTC]
Might be related to bug #53099.
 [2016-07-30 12:45 UTC] ju1ius at laposte dot net
This is not a bug.
You should fix your regexp first.
The pattern you're using is a typical case of catastrophic backtracking.

You can test it here: and see that any regexp engine will have a really hard time matching this pattern.
 [2016-08-20 15:17 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-08-20 15:17 UTC]
> The pattern you're using is a typical case of catastrophic
> backtracking.

Indeed (thanks for the explanation!). Running this regex with PCRE
would quickly bail out with PREG_BACKTRACK_LIMIT_ERROR. AIUI,
request #72777 would similarly solve the issue for mb_ereg().
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 30 10:01:24 2023 UTC