Re: PHP (anti) crash policy?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

On 10/02/2004 06:01 PM, Olaf Van Der Spek wrote:
AFAIK PHP runs safely in multi-threaded servers. What you can't expect is that PHP handles abnormal situations caused by flaws in the external libraries that PHP links with.


When I link with the same library in a C app, this 'abnormal situation' just results in a normal return from 'gzinflate' with an error value.
So why is it a flaw in code from zlib?

That is not the problem. The problem is that zlib does not seem to be able to detect and deal with corrupted streams. That leads to requesting absurd amounts of memory that the PHP memory allocator has no way to distinguish whether it is an intentional memory space request or something case by an abnormal situation.


It is not up to PHP memory allocator to guess what is going on. So it handles like an normal memory allocation, gracefully exits like in any other operations that request space above the configured limits.

If zlib was ready to detect corruption it would never request an absurd amount of memory. I do not think it would be wise to change the PHP memory allocator behavior just to deal with zlib inability to detect corruption before asking for exceedingly large memory blocks.


Maybe you should try this script on a multi-threaded webserver. Is this also caused by flaws in external libraries?

<?php
    function f()
    {
        f();
    }

    f();
?>

The flaw is in your code as nobody should be writing infinite recursion programs.


If you run a similar program in C it will crash exceeding the acceptable calling stack space. I don't know if you do that in PHP that could be avoided as I don't know if PHP can determine whether the stack space was exceeded.

Anyway, the only way to deal with this situation is to let the current process exit as there is no way to recover from this situation that is evidently a bug of the script, not of PHP.


--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux