php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45366 preg_match_all() misses elements (corner-case)
Submitted: 2008-06-26 13:37 UTC Modified: 2008-07-06 18:09 UTC
From: Arne dot Heizmann at csr dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
13 + 9 = ?
Subscribe to this entry?

 
 [2008-06-26 13:37 UTC] Arne dot Heizmann at csr dot com
Description:
------------
The following example code demonstrates that preg_match_all() does not always return all elements as it should.

Almost any change to the input string makes the bug no longer trigger. For example, remove one of the B's, and the bug no longer occurs. Same goes for the regexp: if you change the (?=X|Y) to (?=X) or anything simpler, the bug no longer triggers.

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

    header ('Content-type: text/plain');
    $input = 'A, BBBBBBBB abcd abcd\'y';
    preg_match_all ("/[AB]+(?:\\s*\\w+)*(?=X|Y)|./si", $input, $output);
    var_export ($output);

?>


Expected result:
----------------
array (
  0 => 
  array (
    0 => 'A',
    1 => ',',
    2 => ' ',
    3 => 'B',
    4 => 'B',
    5 => 'B',
    6 => 'B',
    7 => 'B',
    8 => 'B',
    9 => 'B',
    10 => 'B',
    11 => ' ',
    12 => 'a',
    13 => 'b',
    14 => 'c',
    15 => 'd',
    16 => ' ',
    17 => 'a',
    18 => 'b',
    19 => 'c',
    20 => 'd',
    21 => '\'',
    22 => 'y',
  ),
)

Actual result:
--------------
array (
  0 => 
  array (
    0 => 'A',
    1 => ',',
    2 => ' ',
  ),
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-02 02:48 UTC] felipe@php.net
I can reproduce.

PS: The example works fine on pcretest (PCRE version 7.6).
 [2008-07-06 18:09 UTC] nlopess@php.net
backtrack limit reached.
use the following:
ini_set('pcre.backtrack_limit', PHP_INT_MAX);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 21:01:36 2024 UTC