php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37204 Can cause open-ended exception bomb
Submitted: 2006-04-26 00:45 UTC Modified: 2006-04-26 07:38 UTC
From: mailslot at mac dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.1.2 OS: Linux 2.4.21-9.EL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mailslot at mac dot com
New email:
PHP Version: OS:

 

 [2006-04-26 00:45 UTC] mailslot at mac dot com
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-26 03:13 UTC] judas dot iscariote at gmail dot com
the recursion Limit problem is well known (for years), and there is no solution at this time.( because solution should be adecuate for any legitimate use, not just for average use)


Use Xdebug to set a recursion limit in your dev enviroment.
 [2006-04-26 04:58 UTC] mailslot at mac dot com
Okay... no recursion limits. Fine. I'd rather have to enable 
dangerous recursion levels, but I can live without it.

I still think this bug is valid. Could you please respect the 
configuration defines that set limits for script execution 
time and memory usage? These values are completely ignored 
during recursion bombs. Surely that's not expected behavior. 
If they worked as advertised, this bug would never have even 
manifested itself.
 [2006-04-26 07:25 UTC] tony2001@php.net
>These values are completely ignored during recursion bombs.
They ARE respected.
 [2006-04-26 07:26 UTC] mailslot at mac dot com
No. They really aren't. I don't have 2GB RAM set in the config 
file.
 [2006-04-26 07:31 UTC] tony2001@php.net
It means you didn't enable memory limit.
------------

php -r 'function foo() { $a = "text"; foo(); }; foo();'

Fatal error: Allowed memory size of 2097152 bytes exhausted at ..Zend/zend_ptr_stack.h:59 (tried to allocate 137216 bytes) in Command line code on line 1

 [2006-04-26 07:38 UTC] mailslot at mac dot com
Never-mind. I'll fix it myself.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 15:01:33 2024 UTC