php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24460 preg_match crashing on specific pattern/string size
Submitted: 2003-07-02 08:07 UTC Modified: 2005-01-09 23:10 UTC
From: aaanonym at yahoo dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 4.3.11-dev OS: Windows 2000
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: aaanonym at yahoo dot com
New email:
PHP Version: OS:

 

 [2003-07-02 08:07 UTC] aaanonym at yahoo dot com
Description:
------------
It seems that PHP - either at command line, or as an Apache 2.0 module - crashes always against:

preg_match('/(\r|\n|.)*/',$test);

where $test may be ANY string of size >= 2152 bytes

Reproduce code:
---------------
<?PHP

$test='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
preg_match('/(\r|\n|.)*/',$test);

?>

Expected result:
----------------
I was experimenting on the function and trying to match space characters of some kind, against a web page I had downloaded.

This was quite some time ago and I had almost forgotten about the whole error thing. But recently, I downloaded PHP 4.3.2.2 and tryied the code again. I now realized that the error had to do only with the size of the string tested.

Actual result:
--------------
php.exe has generated errors and will be closed by Windows. You will need to restart the program

An error log is being created

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-02 08:08 UTC] sniper@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.
 [2004-09-20 09:25 UTC] aaanonym at yahoo dot com
Well it seems the bug is still alive in PHP-4.3.9RC3. I therefore do what seems appropriate. That is, mentioning the fact and changing the status from Closed to Open.
It is also worth mentioning that the crash is not reproducible in php-5.0.1 with the code as is.
 [2004-12-27 10:46 UTC] aaanonym at yahoo dot com
The crash is still reproducible in the latest 4.x version (4.3.11-dev) I have tested it with.
 [2005-01-09 23:10 UTC] sniper@php.net
It's PCRE limitation, from PCRE docs:

"The  maximum  length of a subject string is the largest 
positive number that an integer variable can hold. However, 
PCRE uses recursion to handle  subpatterns  and indefinite 
repetition. This means that the available stack space may 
limit the size of a subject  string  that  can  be    
processed by certain patterns."

Given long enough subject string, it will crash with PHP 5.0.x, PHP 5.1.x..

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 04:01:32 2024 UTC