php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63651 preg_replace() returns null for very long string
Submitted: 2012-11-30 01:46 UTC Modified: 2012-12-04 07:58 UTC
From: magog dot the dot ogre at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.19 OS: Windows, Unix
Private report: No CVE-ID: None
 [2012-11-30 01:46 UTC] magog dot the dot ogre at gmail dot com
Description:
------------
I have tested and gotten this error on the following two distros:
*5.3.19 for Windows
*5.3.8 for SunOS

Run the code at the pastebin link I've provided. You will see that PHP is 
returning null in a preg_replace function! It occurs in both Windows and Unix. I 
do not know if this is a PHP problem, or a PCRE problem.

Test script:
---------------
http://pastebin.com/PBCDexXH



Expected result:
----------------
A string should be outputted

Actual result:
--------------
Instead, a NULL result is outputted.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-03 02:17 UTC] aharvey@php.net
-Package: *Regular Expressions +Package: PCRE related
 [2012-12-04 01:04 UTC] mail+php at requinix dot net
You're hitting the backtrack limit defined as the pcre.backtrack_limit setting. If 
I up mine to 10000000 (10e6) I get a string(80) "Hello worldHello world..."

Simply put, your regex is too inefficient to work on that $text.
 [2012-12-04 07:58 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2012-12-04 07:58 UTC] nikic@php.net
In particular this part of the regex seems odd: \s*?)\s*\s* Three asterix-quantifier on the same thing in a row, that's something that can easily blow up a regular expression ;)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 15:01:30 2024 UTC