php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53118 preg_split with a subpattern fails on some specific input
Submitted: 2010-10-20 20:44 UTC Modified: 2010-11-10 23:34 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: phpuser at thankyou2010 dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.3 OS: Win/lin
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpuser at thankyou2010 dot com
New email:
PHP Version: OS:

 

 [2010-10-20 20:44 UTC] phpuser at thankyou2010 dot com
Description:
------------
preg_split fails on some specific input, which seems to be caused by a subpattern. If in the testcode I reduce the length of the string in between the middle [..], it works fine.

Test script:
---------------
<?php
$input = '[a][012345678901234 ][a]';

// first match a [, then anything but spaces, end with ]
$tokens = preg_split('/\\[([^\\s]*)*\\]/U', $input);
print_r($tokens);


$tokens = preg_split('/\\[[^\\s]*\\]/U', $input);
print_r($tokens);

Expected result:
----------------
Array
(
    [0] =>
    [1] => [012345678901234 ]
    [2] =>
)
Array
(
    [0] =>
    [1] => [012345678901234 ]
    [2] =>
)

Actual result:
--------------
Array
(
    [0] =>
    [1] => [012345678901234 ][a]
)
Array
(
    [0] =>
    [1] => [012345678901234 ]
    [2] =>
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-10 23:34 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2010-11-10 23:34 UTC] felipe@php.net
This is because the default backtrack_limit size. Set it to a big value so it will work.

e.g.
ini_set('pcre.backtrack_limit', PHP_INT_MAX);
$input = '[a][012345678901234 ][a]';
$tokens = preg_split('/\\[([^\\s]*)*\\]/U', $input);
print_r($tokens);

You can check the preg_last_error() return to detect such errors.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC