php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #6472 str_replace with array causes system hang
Submitted: 2000-08-31 14:12 UTC Modified: 2000-09-03 05:45 UTC
From: ppi at searchy dot net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.0 OS: Linux 2.2.13
Private report: No CVE-ID: None
 [2000-08-31 14:12 UTC] ppi at searchy dot net
I have this function build in a page:

function sponsor1() {
        $time = time();
        echo "\n<center>\n";
        $bannerarray = file("bannercode.txt");
        $count = count($bannerarray);
        for ($i = 0; $i <= count($bannerarray); $i++) {
                $bannerarray[($i)] = str_replace ("%random%", $time, $bannerarray[($i)]);
                echo $bannerarray[($i)];
        }
        echo "\n</center>\n<br>";
}


This will cause in a tremedous memory overflow (the HTTP Deamon needs all memory he can find, so the systems hangs because it's too busy with the swap-partion.

But if I change something in the 'for' loop there's no problem:

$printthis = str_replace ("%random%", $time, $bannerarray[($i)]);
echo $printthis;


This sound me like a little bug in the function 'str_replace'.  When this is not fixed in later versions of PHP (I couldn't find it in the changelogs, so it must be) this bug should be there...

I thought I had configured Php with one of these two :
./configure --with-mysql --with-gd=/usr/lib --with-jpeg-dir=/usr/lib --with-apache=../apache_1.3.12 --enable-track-vars

./configure --with-mysql --with-gd=../gd-1.8.2 --with-jpeg-dir=../jpeg-6b --with-apache=../apache_1.3.12 --enable-track-vars

and apache with this one:

./configure --activate-module=src/modules/php4/libphp4.a --with-layout=config.layout:SuSE --enable-module=so


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-09-03 05:45 UTC] stas@php.net
You have a bug in your script. For condition should be $i < $count, the way it is your array is extending with each loop iteration.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Oct 11 21:00:02 2026 UTC