php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53663 fatal error with bad memory allocation in a script echo & exit
Submitted: 2011-01-06 09:09 UTC Modified: 2013-10-15 11:54 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: sskaje at gmail dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.3.4 OS: Linux/CentOS
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-01-06 09:09 UTC] sskaje at gmail dot com
Description:
------------
Linux/CentOS 5.5 x86_64
PHP 5.3.4
Apache 2.2.16
Tested and can be reproduced under Apache httpd + mod_php5/nginx+fastcgi.
Ok under CLI(at least cant be reproduced under cli.)

I tested a script like below, which was simplified to the minimal.
I was about to dump something, then wrote a var_dump() with an exit;, then i found the php results a fatal error like:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1702113144 bytes) in Unknown on line 0 ...

then In apache error log:

PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0

Apache httpd/nginx usually gives *no response* to the http get request.


check the following code:
uncomment:
  1st __halt_compiler();   .... OK
  2nd __halt_compiler();   .... BAD

then exchange the lines of definitions of class a and b, uncomment:
  1st __halt_compiler();   .... OK
  2nd __halt_compiler();   .... OK


only in 5.3.4, works perfectly in 5.3.3.

Test script:
---------------
<?php
echo 'a';
exit;
#__halt_compiler();
class a extends b{}
class b{}

#__halt_compiler();
#new a;

Expected result:
----------------
a

Actual result:
--------------
error like 
[quote]
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1702113144 bytes) in Unknown on line 0 ...

then In apache error log:

PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0

Apache httpd/nginx usually gives *no response* to the http get request.

[/quote]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-06 09:13 UTC] sskaje at gmail dot com
In fact, there are also error logs in httpd error-log:

[Thu Jan 06 15:15:41 2011] [error] [client 172.16.1.123] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 543450464 bytes) in Unknown on line 0
[Thu Jan 06 15:16:27 2011] [error] [client 172.16.1.123] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 1735355393 bytes) in Unknown on line 0
[Thu Jan 06 15:16:27 2011] [error] [client 172.16.1.123] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 1999598178 bytes) in Unknown on line 0
[Thu Jan 06 15:16:27 2011] [error] [client 172.16.1.123] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 1999598178 bytes) in Unknown on line 0
[Thu Jan 06 15:16:27 2011] [error] [client 172.16.1.123] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 1999598178 bytes) in Unknown on line 0
[Thu Jan 06 15:16:28 2011] [error] [client 172.16.1.123] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 1999598178 bytes) in Unknown on line 0

And the 'PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0' might not be logged by this test script. 

Sorry.
 [2011-01-06 09:17 UTC] sskaje at gmail dot com
The original script is like 

<?php

require(__DIR__ . '/blahsparent.php');
class blahblah extends blahsparent
{
    
}

new blahblah;

only if __halt_compiler(); was added before the line of 'class ....', error would not be triggered.
 [2011-01-16 22:09 UTC] stas@php.net
-Status: Open +Status: Feedback -Package: *Web Server problem +Package: Scripting Engine problem
 [2011-01-16 22:09 UTC] stas@php.net
Could you please post exact script that doesn't work? I tried some permutations of uncommenting stuff in your example and no one of them led to the error.
 [2011-01-17 04:42 UTC] sskaje at gmail dot com
-Status: Feedback +Status: Open
 [2011-01-17 04:42 UTC] sskaje at gmail dot com
@Stas: I upgrade my php to 5.3.5 and the memory allocation message disappeared 
while a *no response* request still exists.

php scripts:

[root@dev test]# more test*.php > /tmp/php.txt
[root@dev test]# cat /tmp/php.txt 
::::::::::::::
test1.php
::::::::::::::
<?php

echo 'a';
exit;
require(__DIR__ . '/Controller.php');

class test extends TestController
{
    public function action()
    {
        $this->output = 'Hello';
        $this->display('raw');
    }
}
new test;
::::::::::::::
test2.php
::::::::::::::
<?php

echo 'a';
exit;

__halt_compiler();
require(__DIR__ . '/Controller.php');

class test extends TestController
{
    public function action()
    {
        $this->output = 'Hello';
        $this->display('raw');
    }
}
new test;
::::::::::::::
test3.php
::::::::::::::
<?php

echo 'a';
exit;

require(__DIR__ . '/Controller.php');

__halt_compiler();
class test extends TestController
{
    public function action()
    {
        $this->output = 'Hello';
        $this->display('raw');
    }
}
new test;
::::::::::::::
test4.php
::::::::::::::
<?php

echo 'a';
exit;

require(__DIR__ . '/Controller.php');

class test extends TestController
{
    public function action()
    {
        $this->output = 'Hello';
        $this->display('raw');
    }
}
__halt_compiler();
new test;


==============
Controller.php:
[root@dev test]# more Controller.php 
<?php
/**
 * 业务 TestController
 * 
 */

require(__DIR__ . '/../ControllerBase.php');

abstract class TestController extends ControllerBase
{
    public function __construct()
    {
        # 禁用 GPC
        $this->diable_gpc();
        
        $this->checkPara();
        $this->action();
    }


    public function __destruct()
    {
        if (!empty($this->output)) {
            # 默认输出
            $this->display();
            unset($this->output);
        }
    }
}

# EOF


==========================
Results:
 test1.php: no http response returned.
 test2.php: http 200 and an output of 'a'
 test3.php: same as test2.php
 test4.php: same as test1.php
 [2011-01-17 04:45 UTC] sskaje at gmail dot com
Whats' more, script without the echo...exit stuff like :

::::::::::::::
test.php
::::::::::::::
<?php

require(__DIR__ . '/Controller.php');

class test extends TestController
{
    public function action()
    {
        $this->output = 'Hello';
        $this->display('raw');
    }
}
new test;


works perfectly.

die('a') performs as same as the echo...exit.
 [2013-03-04 09:18 UTC] dlsniper@php.net
-Status: Open +Status: Feedback
 [2013-03-04 09:18 UTC] dlsniper@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I've just tried to reproduce this against PHP 5.4.12 and Apache and I couldn't get the crash mentioned.
Same goes when trying the scripts against nginx.
Please try to upgrade to a newer version of PHP and check if the problem still exists for you.
I'll close this in 2 weeks if no further feedback.
 [2013-10-15 11:54 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC