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
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: Arne dot Heizmann at csr dot com
New email:
PHP Version: OS:

 

 [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: Sun Jun 16 03:01:28 2024 UTC