Issue Details (XML | Word | Printable)

Key: MDL-11237
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Martin Dougiamas
Reporter: Eloy Lafuente (stronk7)
Votes: 1
Watchers: 2
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

preg_xxxx() critical bug under PHP 5.2.4, tests required...

Created: 13/Sep/07 07:46 AM   Updated: 29/Sep/07 03:08 AM
Return to search
Component/s: Unknown
Affects Version/s: 1.7.3, 1.8.3, 1.9
Fix Version/s: 1.7.3, 1.8.3, 1.9

File Attachments: 1. File preg_match_all_test.php (0.6 kB)

Environment: PHP 5.2.4
Issue Links:
Duplicate
 

Participants: Eloy Lafuente (stronk7), Martin Dougiamas, Penny Leach and Petr Skoda
Security Level: None
Resolved date: 25/Sep/07
Affected Branches: MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE
Fixed Branches: MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE


 Description  « Hide
I was trying to detect why one MSSQL server was causing a lot of problems with simple SQLs when I've discovered that the root of the problem was that one preg_match_all() function wasn't performing its job under BIG texts.

I've attached one script (preg_match_all_test.php) that reproduce the problem in my system. Curiously, the limit seems to be 99998 chars. By adding one more char (99999) the function doesn't work properly.

It's a major problem because it can break tons of things (the mssql_n driver, backup & restore relinking, filters...) potentially anything trying to grep over more than 99998 chars.

Please, can you execute the script and add your results here? TIA!


 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Eloy Lafuente (stronk7) added a comment - 13/Sep/07 07:51 AM
Some results:

PHP: 5.2.4
OS: Darwin mbp 8.10.1 Darwin Kernel Version 8.10.1: Wed May 23 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386 i386
ERROR, preg_match_all() has NOT been able to capture one text of 99999 bytes.

PHP: 5.1.6
OS: Darwin mbp 8.10.1 Darwin Kernel Version 8.10.1: Wed May 23 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386 i386
OK, preg_match_all() has been able to capture one text of 99999 bytes.

PHP: 4.3.10
OS: Darwin mbp 8.10.1 Darwin Kernel Version 8.10.1: Wed May 23 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386 i386
OK, preg_match_all() has been able to capture one text of 99999 bytes.


Penny Leach added a comment - 13/Sep/07 08:01 AM
PHP: 5.2.0-8+etch7

OS: Linux build 2.6.18-4-vserver-686 #1 SMP Thu May 10 01:37:59 UTC 2007 i686

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


Eloy Lafuente (stronk7) added a comment - 13/Sep/07 08:41 AM
Bah!

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.

So, I' would vote to add it to all branches ASAP, or the problem will be breaking a lot of things.

Bah!

Thanks to Penny and Matt!


Eloy Lafuente (stronk7) added a comment - 13/Sep/07 08:47 AM
To have everything inter-linked, this is the bug i submitted to PHP:

http://bugs.php.net/bug.php?id=42649


Martin Dougiamas added a comment - 13/Sep/07 02:43 PM
I've added this to HEAD for a bit of testing before backporting to other branches.

Petr Skoda added a comment - 25/Sep/07 12:28 AM
PHP: 5.2.4
OS: Linux nahore 2.6.22.5-23-default #1 SMP 2007/09/18 05:23:45 UTC i686
ERROR, preg_match_all() has NOT been able to capture one text of 99999 bytes.