|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28317 stack overflow
Submitted: 2004-05-07 18:47 UTC Modified: 2004-05-08 19:36 UTC
From: novicky at aarongroup dot cz Assigned: edink (profile)
Status: Closed Package: PCRE related
PHP Version: 4.3.6 OS: win32
Private report: No CVE-ID: None
 [2004-05-07 18:47 UTC] novicky at aarongroup dot cz
Stack overflow during preg_match() on complex regular expressions used for long data.

As written in pcre.c ...

                   RECURSION IN THE match() FUNCTION

The match() function is highly recursive. Some regular expressions can cause
it to recurse thousands of times. I was writing for Unix, so I just let it
call itself recursively. This uses the stack for saving everything that has
to be saved for a recursive call. On Unix, the stack can be large, and this
works fine.

It turns out that on non-Unix systems there are problems with programs that
use a lot of stack. (This despite the fact that every last chip has oodles
of memory these days, and techniques for extending the stack have been known
for decades.) So....

There is a fudge, triggered by defining NO_RECURSE, which avoids recursive
calls by keeping local variables that need to be preserved in blocks of memory
obtained from malloc instead instead of on the stack. Macros are used to
achieve this so that the actual code doesn't look very different to what it
always used to.

Thus NO_RECURSE should be set in win32 compiler oprions.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-08 19:36 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 24 02:01:29 2024 UTC