From: mailslot at mac dot com
Operating system: Linux 2.4.21-9.EL
PHP version: 5.1.2
PHP Bug Type: Reproducible crash
Bug description: Can cause open-ended exception bomb
Description:
------------
I encountered this problem while debugging an exception logging class.
Infinite recursion problems are a coding mistake, but I've never seen one
take down Apache before. Apache will grow in size until virtual memory
starts swapping. The CPU will be at 100% and eventually, appears to halt.
Limits, obviously, are not being used... yet.
Reproduce code:
---------------
<?php
class Eggception extends Exception
{
public function __construct($ex)
{
parent::__construct($ex);
try {
// let's say that a database object throws
derived Eggception
throw new EggceptionSubclass('It
happens');
// this is valid (not infinitely
recursive)
//throw new Exception('It happens');
} catch (Exception $e) {
// should swallow exception, right?
// not before a never-ending recursive
bomb
}
}
}
class EggceptionSubclass extends Eggception {}
// the following causes a runaway process (memory leak &
// CPU spike) with Apache 2.0.55 and PHP 5.1.2
// rather quickly, all server resources become exhausted
// without proper process limits, potentially crashing the
// entire machine.
throw new Eggception('Exception Bomb');
?>
Expected result:
----------------
A timeout after a large CPU spike... perhaps a stack overflow error.
An exception recursion counter that kills a script whenever it's 1,000
layers deep in an exception stack... that would be great.
Actual result:
--------------
The process (PHP or Apache, depending on which are used to execute the
script) will consume as much memory allowed while pegging the CPU at 100%
utilization. Kill -9 works fine.
Workarounds include ulimit and softlimit.
--
Edit bug report at http://bugs.php.net/?id=37204&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=37204&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=37204&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=37204&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37204&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=37204&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37204&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37204&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37204&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37204&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37204&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=37204&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=37204&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37204&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37204&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37204&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37204&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37204&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37204&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37204&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37204&r=mysqlcfg