php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #34720 Problem when a parenthesised sub exp matches >= 4999996 chars
Submitted: 2005-10-03 21:39 UTC Modified: 2005-10-04 13:10 UTC
From: nuitari at nuitari dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.0.5 OS: Linux
Private report: No CVE-ID: None
 [2005-10-03 21:39 UTC] nuitari at nuitari dot net
Description:
------------
If a paranthesised sub expression matches more then ~4999996 chars, no data will be inserted into the &matches array.

Reducing by 1 the number in str_repeat will cause the script to work.

I have tested this with PHP 4.4.0-gentoo-amd64, 5.0.4-FC4, and 5.0.5-gentoo and all exhebit the same problems. 

The configure line is different on all platforms. php.ini is the default. On the FC4 test there is a 512Mb memory limit.

Reproduce code:
---------------
<?php
  $xml_clean = '<data>';
  $xml_clean .= str_repeat('a',4999996);
  $xml_clean .= '</data>';
  $ret = preg_match("/(<([\w]+)[^>]*>)(.*?)(<\/\\2>)/s", $xml_clean, $match);

  print_r($match);
?>


Expected result:
----------------
Array
(
    [0] => <data>aaa(...)aaa</data>
    [1] => <data>
    [2] => data
    [3] => aaa(...)aaa
    [4] => </data>
)


Actual result:
--------------
Array
(
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-03 22:10 UTC] tony2001@php.net
This is a PCRE limitation,
See bug #34695 for detailed explanation.


 [2005-10-03 23:46 UTC] nuitari at nuitari dot net
Would it be possible to document this in the pcre functions manual ?
 [2005-10-04 09:08 UTC] derick@php.net
That's up for the docteam to decide...
 [2005-10-04 13:10 UTC] nlopess@php.net
the pcre page (http://php.net/pcre) already has a warning about this.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 22 21:00:03 2025 UTC