Re: [PHP-DEV] *crash* on try to find out how many nestinglevelsare allowed From: Zeev Suraski (zeev <email protected>)
Date: 07/09/00

On Sun, 9 Jul 2000, Shane Caraveo wrote:

> My attitude is fix the crash rather than to say 'dont do it and it wont
> crash'. I don't think my attitude is wrong, but maybe it is not
> possible to deal with such a crash effectivly.

Well, it's a bit of a 'DUH' answer, but I generally agree with you. It
just so happens that in this case, as well as in several others (out of
memory, like Stas said), it's quite impossible to recover from it, or even
detect it.

> I agree that writing infinite recursion is not a good thing and should
> not be done. I disagree that it should crash php. Sometimes bugs (in
> scripts, certainly not in php itself ;-) just happen, possibly even
> infinite recursion. On my server, there are several people who write
> scripts, not all being real programmers, I can see stuff happening that
> could lead to a crash, which could take down all the sites on the
> server. If it's possible to prevent such a crash, that is an option I
> would want.

That's definitely a 'DUH!' paragraph :)

> Do you have any remote idea of how much it would slow down php? You and
> Zeev added a lot of performance to php, I would rather sacrifice some of
> that new speed for stability. I may be wrong as I know next to nothing
> about parsers, but I would think it should be possible to check the
> remaining stack size and throw a stack overflow error (if that happens),
> rather than crashing. Doing it this way would also do away with any
> need to count the number of recursions (and have some limit on that).

Just to mention a couple of the problems you'd be facing:

- It's impossible to tell how much stack space you have left (in a
reasonable portable way).
- Every single scope block may cause the stack to overflow. You would
need to add code before each and every block, and specify how many bytes
of stack you're about to try to obtain, and abort if you don't have enough
stack space left.

The only reasonable way to avoid stack overflows, is setting an arbitrary
limit to the function call nesting depth. It won't necessarily save you
(since theoretically, you may overflow the stack during a single function
call, and there's no real way of telling what's a safe number of functions
you can nest).

Zeev

-- 
Zeev Suraski <zeev <email protected>>
http://www.zend.com/

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>