php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66881 Out of memory when spl_autoload_register() called after ini_set()
Submitted: 2014-03-11 03:59 UTC Modified: 2016-05-15 04:22 UTC
Votes:9
Avg. Score:4.4 ± 0.8
Reproduced:8 of 8 (100.0%)
Same Version:2 (25.0%)
Same OS:6 (75.0%)
From: keith at bronstrup dot com Assigned:
Status: No Feedback Package: Reproducible crash
PHP Version: 5.4.26 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-03-11 03:59 UTC] keith at bronstrup dot com
Description:
------------
When using ini_set() to override configuration settings and using spl_autoload_register() with an anonymous function, PHP attempts to allocate nearly 3GB or RAM, causing a fatal error with ini_set() is called before spl_autoload_register(). Works as expected if spl_autoload_register() is called first.

I initially discovered this condition in PHP 5.4.21 and it appears to have persisted after upgrading to 5.4.26 (built with WHM 11.42.0 EasyApache).

I have provided two test scripts, the first of which works as expected (outputs 'Success!'), while the second results in a fatal error resulting from the script attempting to allocate nearly 3GB of RAM. The only difference between these scripts (save for comments) is the order of the ini_set() and spl_autoload_register() functions.

My php.ini is using recommended defaults (from php.ini comments) and my configure line is as follows:
'./configure' '--enable-bcmath' '--enable-calendar' '--enable-exif' '--enable-ftp' '--enable-gd-native-ttf' '--enable-intl' '--enable-libxml' '--enable-mbstring' '--enable-pdo=shared' '--enable-sockets' '--enable-wddx' '--enable-zip' '--prefix=/usr/local' '--with-apxs2=/usr/local/apache/bin/apxs' '--with-bz2' '--with-curl=/opt/curlssl/' '--with-curlwrappers' '--with-enchant=/usr' '--with-freetype-dir=/usr' '--with-gd' '--with-gettext' '--with-icu-dir=/usr' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libexpat-dir=/usr' '--with-libxml-dir=/opt/xml2/' '--with-mcrypt=/opt/libmcrypt/' '--with-mm=/opt/mm/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-mysqli=/usr/bin/mysql_config' '--with-openssl=/usr' '--with-openssl-dir=/usr' '--with-pcre-regex=/opt/pcre' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-png-dir=/usr' '--with-pspell' '--with-tidy=/opt/tidy/' '--with-xpm-dir=/usr' '--with-xsl=/opt/xslt/' '--with-zlib' '--with-zlib-dir=/usr' 

Test script:
---------------
<?php // This fails attempting to allocate nearly 3GM of RAM
ini_set('display_errors', 1);

spl_autoload_register(function ($class) {
	// Doesn't matter what's here, so I've left it empty.
});

die('Success!');
?>
-----
<?php // This outputs 'Success!'
spl_autoload_register(function ($class) {
	// Doesn't matter what's here, so I've left it empty.
});

ini_set('display_errors', 1);

die('Success!');
?>

Expected result:
----------------
As in the first test script:
Success!

Actual result:
--------------
 Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 3050313117 bytes) in /home/bronscon/public_html/keywordcms-oo/failure.php on line 21

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-11 04:05 UTC] keith at bronstrup dot com
This behavior seems to also occur when error_reporting() is called before spl_autoload_register().
 [2014-03-11 05:05 UTC] keith at bronstrup dot com
The supplied test code would actually fail on line 6. The 15 extra lines in my example (error on line 21) are comments, which I removed before posting. Sorry about that.
 [2016-05-06 14:10 UTC] nikic@php.net
-Status: Open +Status: Feedback
 [2016-05-06 14:10 UTC] nikic@php.net
I can't reproduce this issue, and it sounds rather unlikely in the first place. If you still experience this problem in a recent PHP version (PHP >= 5.6), please reopen the bug report.
 [2016-05-15 04:22 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 Apr 25 13:01:30 2024 UTC