|  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
 [2003-07-02 08:07 UTC] aaanonym at yahoo dot com
It seems that PHP - either at command line, or as an Apache 2.0 module - crashes always against:


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

Reproduce code:



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 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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-02 08:08 UTC]
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
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the 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]
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-2023 The PHP Group
All rights reserved.
Last updated: Wed Mar 22 22:03:41 2023 UTC