Moodle

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

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.7.3, 1.8.3, 1.9
  • Fix Version/s: 1.7.3, 1.8.3, 1.9
  • Component/s: Unknown
  • Labels:
    None
  • Environment:
    PHP 5.2.4
  • Affected Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE

Description

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!

Issue Links

Activity

Hide
Eloy Lafuente (stronk7) added a comment -

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.

Show
Eloy Lafuente (stronk7) added a comment - 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.
Hide
Penny Leach added a comment -

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

Show
Penny Leach added a comment - 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
Hide
Eloy Lafuente (stronk7) added a comment -

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!

Show
Eloy Lafuente (stronk7) added a comment - 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!
Hide
Eloy Lafuente (stronk7) added a comment -

To have everything inter-linked, this is the bug i submitted to PHP:

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

Show
Eloy Lafuente (stronk7) added a comment - To have everything inter-linked, this is the bug i submitted to PHP: http://bugs.php.net/bug.php?id=42649
Hide
Martin Dougiamas added a comment -

I've added this to HEAD for a bit of testing before backporting to other branches.

Show
Martin Dougiamas added a comment - I've added this to HEAD for a bit of testing before backporting to other branches.
Hide
Petr Škoda (skodak) added a comment -

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.

Show
Petr Škoda (skodak) added a comment - 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.

People

Dates

  • Created:
    Updated:
    Resolved: