Bug #67467 [NEW]: print_r with $return=true outputs its argument if it is too large

From: Date: Wed, 18 Jun 2014 16:38:51 +0000
Subject: Bug #67467 [NEW]: print_r with $return=true outputs its argument if it is too large
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186240@lists.php.net to get a copy of this message
From:             igor at wiedler dot ch
Operating system: 
PHP version:      5.5.13
Package:          Output Control
Bug Type:         Bug
Bug description:print_r with $return=true outputs its argument if it is too large

Description:
------------
Sufficiently large nested structures will cause print_r to output its
first argument, even if the second $return argument is true.

From a glance at how print_r works, it appears to be using output
buffering internally. If the output written to the buffer is too large,
it will be implicitly flushed.

This is quite a serious problem, as one can easily expose the entire
application state accidentally.

This has been reproduced in the FPM and CLI SAPIs.

Test script:
---------------
<?php
ini_set('memory_limit', '512M');
$a = [];
for ($i = 0; $i < 10000; $i++) {
    $a = [$i, $a];
}
print_r($a, true);


Expected result:
----------------
Blank.

Actual result:
--------------
Array
(
    [0] => 9999
    [1] => Array
        (
            [0] => 9998
            [1] => Array
                (
                    [0] => 9997
                    [1] => Array
                        (

...

-- 
Edit bug report at https://bugs.php.net/bug.php?id=67467&edit=1
-- 



Thread (6 messages)

« previous php.bugs (#186240) next »