|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-04-18 18:04 UTC] realbora at gmx dot de
Description:
------------
"str_replace" causes buffer overflow when using regexp's as replace!
When using regexp`s as the replacement in "str_replace" a system hangup can cause.
Not ever, but in general is this the failure.
Reproduce code:
---------------
$regExp=array(":","-","{","}","(",")","~","[","]","#","|");
$sql2=mysql_query('select * from smilies;');
for($i=0;$temp2=mysql_fetch_array($sql2);$i++){
$smilie[$i]=$temp2['smilie'];
for($j=0;$j<=count($regExp);$j++){
$smilie[$i]=str_replace($regExp[$j],"\\"."\\".$regExp[$j],$smilie[$i]);
}
$file[$i]='<img border="0" src="./bilder/smilies/'.$temp2['file'].'">';
$neu_post=preg_replace("/$smilie[$i]/",$file[$i],$neu_post);
echo $smilie[$i].'<br>';
$neu_post1=substr($neu_post, 0, 60+$x);
}
Expected result:
----------------
Memoryuse grows very fast until system hangup.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 13:00:01 2025 UTC |
I don`t have a Webserver with W2K on the web. I only got this problem on my home-pc with a lokal webserver (IIS 5) for testing. You don't need a database or any other resources for this script. You only have do modify it a bit! modified script without a need of resources: $smilie=array(":-)",";-)",":-}","}:-)",":-#",":|"); $regExp=array(":","-","{","}","(",")","~","[","]","#","|"); $sql2=mysql_query('select * from smilies;'); for($i=0;$i<=count($smilie);$i++){ for($j=0;$j<=count($regExp);$j++){ $smilie[$i]=str_replace($regExp[$j],"\\"."\\".$regExp[$j],$smilie[$i]) ; } $file[$i]='<img border="0">'; $neu_post=preg_replace("/$smilie[$i]/",$file[$i],$neu_post); echo $smilie[$i].'<br>'; $neu_post1=substr($neu_post, 0, 60+$x); }