#45366 [Ver->Bgs]: preg_match_all() misses elements (corner-case)

From: Date: Sun, 06 Jul 2008 18:09:45 +0000
Subject: #45366 [Ver->Bgs]: preg_match_all() misses elements (corner-case)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126324@lists.php.net to get a copy of this message
ID: 45366 Updated by: nlopess@php.net Reported By: Arne dot Heizmann at csr dot com -Status: Verified +Status: Bogus Bug Type: PCRE related Operating System: * PHP Version: 5.2.6 New Comment: backtrack limit reached. use the following: ini_set('pcre.backtrack_limit', PHP_INT_MAX); Previous Comments: ------------------------------------------------------------------------ [2008-07-02 02:48:52] felipe@php.net I can reproduce. PS: The example works fine on pcretest (PCRE version 7.6). ------------------------------------------------------------------------ [2008-06-26 13:37:36] 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 => ' ', ), ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45366&edit=1

« previous php.bugs (#126324) next »