php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70675 method_exists from extended class causes memory allocation issues
Submitted: 2015-10-09 07:56 UTC Modified: 2015-10-10 06:36 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: maartensc at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 7.0.0RC4 OS: FreeBSD 10.1-RELEASE
Private report: No CVE-ID: None
 [2015-10-09 07:56 UTC] maartensc at gmail dot com
Description:
------------
Good day,

I actually have PHP 7.1.0-dev version compiled from GIT. I used the following to compile:

./configure --enable-fpm --with-pdo-mysql --with-pear --with-openssl --with-curl --with-mcrypt --with-zlib --enable-zip --with-png-dir --with-jpeg-dir --with-config-file-path=/usr/local/php --enable-debug --enable-maintainer-zts --enable-cgi --enable-cli


PHP 7.1.0-dev (cli) (built: Oct  8 2015 14:00:51) ( ZTS DEBUG )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies

nginx version: nginx/1.8.0


When I run my simplified script below I get the following error.
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted at /root/php-src/Zend/zend_execute.c:151 (tried to allocate 262176 bytes) in /usr/local/www/dev/Logs/test.php on line 4

Fatal error: Allowed memory size of 134217728 bytes exhausted at /root/php-src/Zend/zend_execute.c:151 (tried to allocate 262176 bytes) in /usr/local/www/dev/Logs/test.php on line 4

The dev machine has 1GB of memory. Memory usage details below.
root@devwebserver:/usr/local/www/dev/Logs # vmstat 
 procs      memory      page                    disks     faults         cpu
 r b w     avm    fre   flt  re  pi  po    fr  sr da0 cd0   in   sy   cs us sy id
 0 0 19   1749M   235M    69   0   0   0    80   3   0   0    2  191   88  0  0 100


The above error shows from CLI and when doing request via NGINX -> PHP-FPM.


I have really simplified my script to replicate this issue and as is it might not make too much sense to use this as is.




Test script:
---------------
<?php
class BaseController{
    public function __call(string $Action, array $Data){
        if (method_exists($this, $Action . "Action")) {
        } elseif (method_exists($this, "DefaultAction") and $this->DefaultAction($Action, $Data)) {
            exit;
        }
    }
}
class TestPage extends BaseController{
    private function DefaultAction(string $Action, array $Data): bool{
        return false;
    }
}
$testpage = new TestPage();
$testpage->Show();

Expected result:
----------------
Currently the output for this script should be nothing.

Actual result:
--------------
root@webserver:/usr/local/www/dev/Logs # gdb php 
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) run /usr/local/www/dev/Logs/test.php
Starting program: /usr/local/bin/php /usr/local/www/dev/Logs/test.php
[New LWP 100084]
PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted at /root/php-src/Zend/zend_execute.c:151 (tried to allocate 262176 bytes) in /usr/local/www/dev/Logs/test.php on line 4

Fatal error: Allowed memory size of 134217728 bytes exhausted at /root/php-src/Zend/zend_execute.c:151 (tried to allocate 262176 bytes) in /usr/local/www/dev/Logs/test.php on line 4

Program exited with code 0377.
(gdb) bt
No stack.
(gdb) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-09 13:30 UTC] maartensc at gmail dot com
-Summary: Fatal error: Allowed memory size:zend_execute.c:151 +Summary: method_exists from extended class causes memory allocation issues
 [2015-10-09 13:30 UTC] maartensc at gmail dot com
Updated summary to be more accurate.
 [2015-10-09 18:19 UTC] marcio@php.net
This doesn't seem to be a bug. Your __call method has infinite recursion. Consider this other example with 'DefaultAction' being defined as 'protected' instead of 'private': https://3v4l.org/l37O8
 [2015-10-10 06:36 UTC] maartensc at gmail dot com
-Status: Open +Status: Closed
 [2015-10-10 06:36 UTC] maartensc at gmail dot com
Hi Marcio,

thank you! It is working!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 23:01:28 2024 UTC