php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48047 preg_replace returns NULL over string size
Submitted: 2009-04-22 13:53 UTC Modified: 2009-04-22 13:58 UTC
From: goriol at technema dot fr Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 5.2.9 OS: Windows XP
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: goriol at technema dot fr
New email:
PHP Version: OS:

 

 [2009-04-22 13:53 UTC] goriol at technema dot fr
Description:
------------
I found a situation where preg_replace returns NULL instead of the expected string. The regexp I use is (perhaps) erroneous: "/^\s*(.*?)\s*$/s"
But when the string size is less than 49997 characters, the function returns the string properly. Over that size, the function returns NULL.

Reproduce code:
---------------
$a = str_repeat('a', 49998);
$a = preg_replace('/^\s*(.*?)\s*$/s', '$1', $a);


Expected result:
----------------
$a

Actual result:
--------------
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-04-22 13:58 UTC] scottmac@php.net
preg_last_error() returns 2 which is PREG_BACKTRACK_LIMIT_ERROR.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Nov 28 05:03:12 2021 UTC