php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40812 PHP sometimes returns blank document when allocating too much memory
Submitted: 2007-03-15 08:50 UTC Modified: 2007-03-23 01:00 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: chmelar at busche dot sk Assigned:
Status: No Feedback Package: Unknown/Other Function
PHP Version: 5.2.1 OS: Fedora Linux 2.6
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:
2 + 48 = ?
Subscribe to this entry?

 
 [2007-03-15 08:50 UTC] chmelar at busche dot sk
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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-15 13:02 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2007-03-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2007-04-17 13:01 UTC] mick at aplicube dot com
Win2K SVP4
PHP5.2.1
Apache2.2.4
MySQL 5.0.37

CMS joomla1.5  debugged [i.e. removed errors found so far]

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 16 bytes) in C:\7\htdocs\libraries\phputf8\utils\unicode.php on line 49
line where php is moaning..

     $in = ord($str{$i});


Sometimes an empty page will occure but with correct html...head...body tags etc.

Same phenomen as in the previous message description explained.

Latest php ...the same fatal error will occure [on my system].

php 5.1.x, php5.2.0 won't produce this error.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Oct 02 06:05:52 2022 UTC