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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC