note 66799 added to language.exceptions
| From: | nitrous at fuckoff dot com | Date: | Mon, 29 May 2006 20:48:22 +0000 |
| Subject: | note 66799 added to language.exceptions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-112508@lists.php.net to get a copy of this message | ||
Infinite recursion:
There are limits with recursion when using functions. I can only seem to achieve 48,000 levels
before segfault. When I implement recursion with Exceptions (a gross hack), I have an unlimited call
stack (limited by RAM). If you modify the included code to pass parameters, you can perform
extremely deep recursive function calls.
This code block demonstrates the uncapped limits in PHP and the ability to wreck your machine using
this method. Be careful! A static reference count in the constructor and destructor is advised to
limit the recursion depth manually.
class Eggception extends Exception
{
public function __construct($ex)
{
parent::__construct($ex);
try {
throw new EggceptionSubclass('Do math here');
} 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)
// without proper process limits, potentially crashing the
// entire machine.
throw new Eggception('Do my func');
----
Server IP: 66.163.161.117
Probable Submitter: 63.214.184.6
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.exceptions.php
Edit -- http://master.php.net/note/edit/66799
Del: integrated -- http://master.php.net/note/delete/66799/integrated
Del: useless -- http://master.php.net/note/delete/66799/useless
Del: bad code -- http://master.php.net/note/delete/66799/bad+code
Del: spam -- http://master.php.net/note/delete/66799/spam
Del: non-english -- http://master.php.net/note/delete/66799/non-english
Del: in docs -- http://master.php.net/note/delete/66799/in+docs
Del: other reasons-- http://master.php.net/note/delete/66799
Reject -- http://master.php.net/note/reject/66799
Search -- http://master.php.net/manage/user-notes.php