#40812 [NEW]: PHP sometimes returns blank document when allocating too much memory
From: chmelar at busche dot sk
Operating system: Fedora Linux 2.6
PHP version: 5.2.1
PHP Bug Type: Output Control
Bug description: PHP sometimes returns blank document when allocating too much memory
Description:
------------
Sometimes when PHP tries to allocate too much memory, it crashes without
an error message and produces a blank screen.
Reproduce code:
---------------
This occurs after running this script (it doesn't crash always, so try to
refresh 5-10 times until it returns nothing (zero sized reply)):
<?php
function myErrorHandler($errno, $errmsg, $filename, $linenum, $vars) {
ini_set('memory_limit', '10M');
echo "Error occured";
die();
};
ini_set('memory_limit', '1M');
error_reporting(E_ALL | E_STRICT);
set_error_handler('myErrorHandler');
$a=array();
$aLen=rand(2048,65535);
echo "trying to initialize an array with ".$aLen." items (randomly
generated)...
\n";
$i=0;
while ($i<$aLen && (rand(1,65534)<65533 || rand(1,65534)>2)) {
$varName='a_'.chr(rand(65,90)).chr(rand(65,90)).chr(rand(65,90)).chr(rand(65,90)).chr(rand(65,90));
$$varName=rand(0,255);
//$a[]=rand(0,255);
$i++;
};
echo "successfuly initialized an array with ".count($a)." items. please
refresh";
?>
Expected result:
----------------
Usually (in normal cases) the error handler should write "Error occured"
to the output and end the script.
Looks like the code allocates small chunks of memory (about 40 bytes), and
when it tries to allocate the next chunk and it doesn't have enough memory,
it tries to trigger an error, BUT there is the problem that by triggering
error 4 or 5 parameters are passed to the error handler - that means PHP
needs to allocate space for them. But the error message text itself has
more than 100 charactes, so it doesn't fit to the free memory block and
PHP just crashes. So it seems to be a PHP bug.
Actual result:
--------------
Zero sized reply (MS IE7) or blank screen (FF 1.5)
--
Edit bug report at http://bugs.php.net/?id=40812&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40812&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40812&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40812&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40812&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=40812&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40812&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40812&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40812&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40812&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40812&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=40812&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=40812&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40812&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40812&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40812&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40812&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40812&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40812&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40812&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40812&r=mysqlcfg
Thread (3 messages)
- chmelar at busche dot sk