From: keith at bronstrup dot com
Operating system: Linux
PHP version: 5.4.26
Package: Reproducible crash
Bug Type: Bug
Bug description:Out of memory when spl_autoload_register() called after ini_set()
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
--
Edit bug report at https://bugs.php.net/bug.php?id=66881&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66881&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66881&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66881&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66881&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66881&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66881&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66881&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66881&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66881&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66881&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66881&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66881&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66881&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66881&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66881&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66881&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66881&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66881&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66881&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66881&r=mysqlcfg