|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32029 PCRE bugs under Windows XP
Submitted: 2005-02-19 20:42 UTC Modified: 2005-06-07 01:00 UTC
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: craig at unclecraig dot com Assigned:
Status: No Feedback Package: PCRE related
PHP Version: 5CVS, 4CVS (2005-02-19) OS: win32 only
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: craig at unclecraig dot com
New email:
PHP Version: OS:


 [2005-02-19 20:42 UTC] craig at unclecraig dot com
I'm using the latest snap shot (php4-win32-STABLE-200502191330) on Win XP with Apache 2.

I've experienced a number of problems with pgrep_replace/pgrep_match that only occur under windows.  The same code works fine under linux.

The example below is easily reproduced.  The expression splits a file into it's components - path, name, ext (where ext can be multi part)

When the name part exceeds 12 chars, the expression no longer matches.  This is not the case using RegExp Coach on the same platform.

I also get a problem when using the following:
// Remove C comments
$content = preg_replace( "|\/\*((?!\*\/).)*\*\/|is", "", $content);

This used to work fine, then suddenly it stopped, no error is returned execution just halts here and the document returns no data.  I made no modification to the PHP base, just some of the files that were being parsed got a bit bigger so this code be a memory issue??? Still no errors are generated php just halts.  (This is one reason I increased the memory_limit directive in the php.ini file)

Please help, as I can no longer debug under windows, and I face having to rewrite large chunks of code to avoid using preg functionality!

-- PHP.INI --
max_execution_time = 150
memory_limit = 64M
debugger.JIT_host = clienthost
debugger.JIT_port = 7869
mime_magic.magicfile = "C:\Program Files\Apache Group\Apache2\conf\magic"

Reproduce code:
echo "\n".preg_match('|^((?:(?:\/?[^\/]*)*)(?:\/))?([^\/\.]+)\.([^\/]+)$|i','',$parts);
echo "\n".preg_match('|^((?:(?:\/?[^\/]*)*)(?:\/))?([^\/\.]+)\.([^\/]+)$|i','',$parts);

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-20 19:58 UTC] craig at unclecraig dot com
Please note I am aware of and use the 'basename' and 'dirname' functions.  The above is just a reproduceable example to demonstrate the the PCRE code is unreliable on Win XP, at least for me.
 [2005-02-21 18:59 UTC] craig at unclecraig dot com
Replacing '|\/\*((?!\*\/).)*\*\/|is' with '|\/\*.*?\*\/|is' is more efficient preventing greedy matching rather than using look ahead.  Nonetheless, the original reg-ex is still techinically valid and works under linux, so it's still technically a bug.  At a guess there is a memory issue when using look-ahead (and possible look-behind) in PCRE under windows.
 [2005-02-21 19:05 UTC]
It works in the same way for me under Linux, so I think it's probably PCRE problem and PHP has nothing to do with it.
 [2005-02-21 19:21 UTC] craig at unclecraig dot com
I'm developing on a Windows box for submission on a linux server so I run the same code on both windows and linux, and can assure you that for me both examples given run without problems on Linux.  I can accept this is a PCRE bug/problem however, as the PCRE libraries are obviously different on both platforms.  But running RegExp Coach on the same platform caused no problems with the same input and expression.  This suggests that it may be an interaction between PHP and the PCRE code - perhaps in the way it allocates memory (look-aheads are quite memory intensive I believe).

Nonetheless, if it is a PCRE bug, is there any way for PHP to raise an error, rather than terminating without warning.  It took a long time to track the bug down by stepping through code until the correct line was isolated, as PCRE is implemented as a built-in function, it shouldn't cause the runtime to terminate unexpectedly (ie crash).

The nature of any test is to implement controls and limit the variables, as you can see from above, I have demonstrated satisfactorily that the regular expression works without issue on multiple platforms with the same input, except when running with PHP under windows, i.e.

PHP, linux -> Pass
RegEx Coach, Windows -> Pass
PHP, Windows -> Fail

This demonstrates that the PCRE code works successfully except under the one condition where the variable was PHP.  It is unlikely therefore that there is no issue with the way PHP uses the PCRE code, hence the bug report was filed here.

Thank you
 [2005-06-07 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 12:01:28 2024 UTC