php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66928 ob_start()/ob_end_clean() and memory_limit
Submitted: 2014-03-18 19:56 UTC Modified: 2014-12-30 10:42 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: leon at struktur dot de Assigned:
Status: No Feedback Package: Output Control
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
26 - 14 = ?
Subscribe to this entry?

 
 [2014-03-18 19:56 UTC] leon at struktur dot de
Description:
------------
COPY FROM : https://bugs.php.net/bug.php?id=45392
STILL NOT FIXED, BUT BUG IS CLOSED !!


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.

Test script:
---------------
<?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

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
 [2014-03-18 20:22 UTC] leon at struktur dot de
New test script:

$img = @imagecreatefromstring(file_get_contents($file));
if($img !== false)
{
	imagealphablending($img, false);
	imagesavealpha($img, true);
	
	ob_start();
	imagepng($img);
	$img_content = ob_get_clean();
	
	imagedestroy($img);
	
	$img_content = base64_encode($img_content);
	
	return $img_content;
}

Output: "* PNG IHDR**"


New test #2 script:

$img = @imagecreatefromstring(file_get_contents($file));
if($img !== false)
{
	imagealphablending($img, false);
	imagesavealpha($img, true);
	
	ob_start();
	echo 'LALALA';
	imagepng($img);
	$img_content = ob_get_clean();
	
	imagedestroy($img);
	
	$img_content = base64_encode($img_content);
	
	return $img_content;
}

Output: "LALALA* PNG IHDR**"



BTW: It works (I get no output) when I add ini_set('memory_limit', '-1');
 [2014-07-06 02:14 UTC] yohgaki@php.net
-Status: Open +Status: Feedback
 [2014-07-06 02:14 UTC] yohgaki@php.net
[yohgaki@dev PHP-5.5]$ cat t.php
<?php
ob_start();
$i = 0;
while($i++ < 1024*4)  {
        echo str_repeat("a", 1024);
}
ob_end_clean();

?>

END
[yohgaki@dev PHP-5.5]$ ./php-bin -d error_reporting=-1 -d memory_limit=400000 t.php

Fatal error: Allowed memory size of 400000 bytes exhausted at /home/yohgaki/git/oss/php.net/PHP-5.5/Zend/zend_stack.c:37 (tried to allocate 512 bytes) in /home/yohgaki/workspace/ext/git/oss/php.net/PHP-5.5/t.php on line 4

It seems working correctly.
Are you sure you have reached memory_limit?
 [2014-07-06 02:14 UTC] yohgaki@php.net
[yohgaki@dev PHP-5.5]$ cat t.php
<?php
ob_start();
$i = 0;
while($i++ < 1024*4)  {
        echo str_repeat("a", 1024);
}
ob_end_clean();

?>

END
[yohgaki@dev PHP-5.5]$ ./php-bin -d error_reporting=-1 -d memory_limit=400000 t.php

Fatal error: Allowed memory size of 400000 bytes exhausted at /home/yohgaki/git/oss/php.net/PHP-5.5/Zend/zend_stack.c:37 (tried to allocate 512 bytes) in /home/yohgaki/workspace/ext/git/oss/php.net/PHP-5.5/t.php on line 4

It seems working correctly.
Are you sure you have reached memory_limit?
 [2014-12-30 10:42 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Sep 30 23:05:52 2022 UTC