php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27310 preg_replace regexp causes PHP to die
Submitted: 2004-02-18 09:03 UTC Modified: 2004-02-18 11:46 UTC
From: paul at pscs dot co dot uk Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 4.3.5RC3 OS: Win32 (Windows XP)
Private report: No CVE-ID: None
 [2004-02-18 09:03 UTC] paul at pscs dot co dot uk
Description:
------------
It looks as if when PHP is doing preg_replace and there are a lot of () values, then it just dies

With my example code, it'll die when doing preg_replace

I've tried a few values of $regexp on line 2

/<(.|\n)*>/  - it dies
/<(.)*>/     - it dies
/<.*>/       - it works fine

If the $test string is 1844 characters long it works fine, if it's 1845 characters long it dies.

It doesn't matter whether the string actually matches or not, it's the number of characters it's trying to match.

The problem doesn't seem to happen with preg_match



Reproduce code:
---------------
<?php
$regexp = "/<(.|\n)*>/";
$stringlength = 1845;

echo "test start \n";
$test = '<' . str_repeat('x', $stringlength - 1);

$test = preg_replace($regexp,"",$test);
echo "test done\n";
?>


Expected result:
----------------
test start
test done

Actual result:
--------------
<nothing>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-18 11:46 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

Try searching the bug db before submiting YET another report about same issue. (and it's PCRE limitation, not bug)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 15:01:31 2024 UTC