php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26363 preg_replace() crashes PHP
Submitted: 2003-11-23 09:25 UTC Modified: 2003-11-24 11:28 UTC
From: prof_moriarty at veryfast dot biz Assigned:
Status: Not a bug Package: Regexps related
PHP Version: 4.3.4 OS: win 98SE
Private report: No CVE-ID: None
 [2003-11-23 09:25 UTC] prof_moriarty at veryfast dot biz
Description:
------------
There seem to be some major issues with preg_replace in this version.

See code actual and reproducable for explanations

Reproduce code:
---------------
$string = "ship_id = '17' ||";

$string = preg_replace("/\|\| $/", "", $string);

echo $string;

Expected result:
----------------
SHOULD result in

ship_id = '17'


being printed to the screen.

Actual result:
--------------
PHP crashes.
Indeed it would seem absolutely anything i enter as either the regexp, or the string will crash it. Even if both are blank.


Below is the 'details' of the error (as gained from windows thing):

"
PHP caused an invalid page fault in
module <unknown> at 0000:854fd78b.
Registers:
EAX=0000004c CS=016f EIP=854fd78b EFLGS=00010246
EBX=0063f474 SS=0177 ESP=0063f330 EBP=10135328
ECX=00000000 DS=0177 ESI=0000004c FS=96a7
EDX=0000008a ES=0177 EDI=007d68cc GS=0000
Bytes at CS:EIP:
00 2e 00 05 00 2e 00 05 00 2e 00 05 00 2e 00 05 
Stack dump:
011750f4 ffffffff 10135328 10135328 01010101 01010101 01010101 00100101 0000004c 00100010 01820010 00000000 00000000 0102014c 01020102 01020102 
"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-23 13:29 UTC] scottm at spamcop dot net
Your regex wont work.

Your trying to match || followed by a space at the end of the string.

Where you have space then the double pipes in $string.

Using
------
$string = "ship_id = '17' ||";

$string = preg_replace("/ \|\|$/", "", $string);

echo $string;

I get no
ship_id = '17'
as exepcted
 [2003-11-23 21:15 UTC] sniper@php.net
Does not crash with linux.

 [2003-11-24 11:22 UTC] prof_moriarty at veryfast dot biz
But the regexp DOES work with 3.4.2!!! And earier version too.

What the regexp ("/\|\| $/") does is:

\|\| = looking for ||

" " = looking for space

$ = the above must be at the end of the string


No piping or anything else required there.

And the string it's replacing is something more like:
$del_str .= "ship_id = '17' || "; (with an extra space at the end (typo my missing it out on the original post)). That'd be why you thought it wouldn't work. Sorry. ;)
 [2003-11-24 11:28 UTC] prof_moriarty at veryfast dot biz
Typo in last post. read 4.3.2 in place of 3.4.2...

I've just done some more testing of this, and it's now working?!?!?!??! Which has made me REALLY baffled

I had two scripts that wouldn't work under 4.3.4. I narrowed it down to that line of code in one of them (the other was 2000 lines and would have taken days to debug :) )
Anyhow, both scripts now work. As does my 3 line test script which invariably crashed yesterday.

I havn't altered my installation of PHP, apache, or mysql since yesterday!!!

This is really, REALLY weird...

Untill this happens again, i'll give this bug a 'bogus' rating.
But i'd suggest someone look into it.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Nov 24 21:01:23 2020 UTC