php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45392 ob_start()/ob_end_clean() and memory_limit
Submitted: 2008-06-29 22:30 UTC Modified: 2009-05-07 13:36 UTC
Votes:3
Avg. Score:3.3 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: flebron at bumeran dot com Assigned: iliaa
Status: Closed Package: Output Control
PHP Version: 5CVS-2008-11-01 OS: *
Private report: No CVE-ID:
 [2008-06-29 22:30 UTC] flebron at bumeran dot com
Description:
------------
When memory_limit is reached, and one is using the output buffering functions, instead of just dying with an "out of memory" error, the contents of the buffer are spilled onto stdout.
The output_buffering ini setting wasn't set to any particular limit.

Reproduce code:
---------------
<?php
ob_start();
$i = 0;
while($i++ < 10000000)  {
        echo str_repeat("lol", 42);
}
ob_end_clean();
/*Note that the 10,000,000 number varies according to your memory_limit*/

Expected result:
----------------
STDERR: Fatal error: Allowed memory size of 134217728 bytes exhausted at /home/flebron/cvs/php/php5.3-200806291230/main/output.c:395 (tried to allocate 133693441 bytes) in /home/flebron/cvs/php/ob.php on line 5

STDOUT: Nothing

Actual result:
--------------
STDERR: Fatal error: Allowed memory size of 134217728 bytes exhausted at /home/flebron/cvs/php/php5.3-200806291230/main/output.c:395 (tried to allocate 133693441 bytes) in /home/flebron/cvs/php/ob.php on line 5

STDOUT: The text in the buffer is printed to stdout (millions of "lolol"s).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-14 11:26 UTC] jani@php.net
This slightly modified script shows the bug without massive output:

<?php
ini_set('memory_limit', 100);
ob_start();
$i = 0;
while($i++ < 5000)  {
  echo str_repeat("lol", 42);
}
ob_end_clean();
?>

 [2008-09-17 00:20 UTC] iliaa@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2008-11-02 13:58 UTC] jani@php.net
The test for this bug fails in both branches.
 [2008-12-01 20:45 UTC] iliaa@php.net
Works fine for me using your example script in 5.3, the patch never went 
into 5.2 as it is a little risky for a stable release.
 [2009-04-30 11:59 UTC] hwallenstone at gmx dot de
Changelog for 5.2.7 states this Bug as "Fixed", although it still there in 5.2.8. As it never went into 5.2, the Changelog should be changed.
 [2009-12-11 15:42 UTC] svn@php.net
Automatic comment from SVN on behalf of jani
Revision: http://svn.php.net/viewvc/?view=revision&revision=291992
Log: MF53:- Fixed bug #45392 (ob_start()/ob_end_clean() and memory_limit) #Ilia..
 [2011-08-24 15:56 UTC] joey@php.net
Automatic comment from SVN on behalf of joey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=315430
Log: Fix tests/lang/bug45392.phpt to log expected error when run with -n flag
 [2011-12-13 10:56 UTC] jakoch at web dot de
Test still fails in head:
http://gcov.php.net/viewer.php?
version=PHP_HEAD&func=tests&file=tests%2Flang%2Fbug45392.phpt
 [2014-03-13 15:50 UTC] php at speed dot 1s dot fr
Why is this issue marked as "Closed"? Doesn't seem to be fixed.
Using PHP 5.3.3, error_reporting set to -1.

Code:
----------
$img = @imagecreatefromstring(file_get_contents($file));
ob_start();
imagepng($img);
$contents = ob_get_clean();
imagedestroy($img);

Output:
----------
*PNG IHDR ***

(These seem to be the first few characters of the image)

Log:
----------
PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 10240 bytes)

Please reopen this issue.
 [2014-03-13 15:50 UTC] php at speed dot 1s dot fr
Why is this issue marked as "Closed"? Doesn't seem to be fixed.
Using PHP 5.3.3, error_reporting set to -1.

Code:
----------
$img = @imagecreatefromstring(file_get_contents($file));
ob_start();
imagepng($img);
$contents = ob_get_clean();
imagedestroy($img);

Output:
----------
*PNG IHDR ***

(These seem to be the first few characters of the image)

Log:
----------
PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 10240 bytes)

Please reopen this issue.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 07:02:02 2014 UTC