php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42649 preg_match_all doesn't capture more than 99998 bytes
Submitted: 2007-09-13 00:17 UTC Modified: 2007-09-13 07:48 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: stronk7 at moodle dot org Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.4 OS: potentially any
Private report: No CVE-ID: None
 [2007-09-13 00:17 UTC] stronk7 at moodle dot org
Description:
------------
Trying to capture more than 99998 bytes from one string captures nothing. Same behavior happens also in other PCRE functions.

You can see more test results in the original place where was reported: http://tracker.moodle.org/browse/MDL-11237

Reproduce code:
---------------
<?php

/// Change this if you want, but 99999 is the limit in my system (Darwin mbp 8.10.1)
    $numchars = 99999;

/// Test begins here
    echo 'PHP: ' . phpversion() . '<br />';
    echo 'OS: ' . php_uname() . '<br />';
    $all = '';

    for($i=0; $i<$numchars-2; $i++) {
        $all .= 'x';
    }
    $all = '@' . $all . '@';
    preg_match_all('/@(.*?)@/is', $all, $results);
    if ($results[0]) {
        echo 'OK, preg_match_all() has been able to capture one text of ' . strlen($results[0][0]) . ' bytes.<br />';
    } else {
        echo 'ERROR, preg_match_all() has NOT been able to capture one text of ' . strlen($all) . ' bytes.<br />';
    }

?>

Expected result:
----------------
It should show:

OK, preg_match_all() has been able to capture one text of 99999 bytes

Actual result:
--------------
ERROR, preg_match_all() has NOT been able to capture one text of 99999 bytes

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-13 00:44 UTC] stronk7 at moodle dot org
UHm...

It seems that, since 5.2.0 it's necessary to adjust the "pcre.backtrack_limit' setting to allow more chars to be returned (in ungreedy matches). So, something like:

 ini_set('pcre.backtrack_limit', 20971520); /// 20 MB

will allow up to 20MB of text to be matched. 

Radical change (without notices?) from previous versions...uhm.

Ciao :-)
 [2007-09-13 07:48 UTC] jani@php.net
Expected behaviour. And it was a bug fix to prevent crashes / out of memory issues. Not bug -> bogus.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Oct 20 03:01:26 2019 UTC