Bug #66928 [Opn]: ob_start()/ob_end_clean() and memory_limit

From: Date: Tue, 18 Mar 2014 20:22:51 +0000
Subject: Bug #66928 [Opn]: ob_start()/ob_end_clean() and memory_limit
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184827@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66928&edit=1 ID: 66928 User updated by: leon at struktur dot de Reported by: leon at struktur dot de Summary: ob_start()/ob_end_clean() and memory_limit Status: Open Type: Bug Package: Output Control Operating System: * PHP Version: Irrelevant Block user comment: N Private report: N New Comment: 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'); Previous Comments: ------------------------------------------------------------------------ [2014-03-18 19:56:50] 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). ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66928&edit=1

« previous php.bugs (#184827) next »