From:             cnww at hfx dot andara dot com
Operating system: Debian GNU/Linux
PHP version:      5.2.0
PHP Bug Type:     Arrays related
Bug description:  serialize() consumes insane amount of RAM

Description:
------------
When called on a tree implemented as a multi-dimensional array occupying
something like 60MB of RAM serialize fails with an error like:

Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to
allocate 6282420 bytes) in /var/www/lib/metacache.php on line 105

So either the memory allocation system is busted or the serialization of
~60MB of data (actually the full text version is only 9.1MB) requires over
1GB of memory.

Reproduce code:
---------------
The line that is actually failing is:

$meta_ser = serialize( &$metacache_buf );

For obvious reasons I have not posted the whole array here. 

I created an example program that reproduces the problem using an array of
242,919 strings made with var_export() from the directory listing of a
Windows machine's D: drive.

You can get the code from:
http://arachne.k-pcltee.com/~cnww/serialbug.bz2

The example program seems to require around 52MB of RAM to create the
array, so if you're using the default 8MB limit it will fail before it
gets to the serialize() call. Any limit of 64MB or greater seems to result
in it failing during serialize().

Expected result:
----------------
It should print "Exiting normally"

Actual result:
--------------
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to
allocate 6010844 bytes) in /tmp/serialbug.php on line 313030

-- 
Edit bug report at http://bugs.php.net/?id=39736&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=39736&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=39736&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=39736&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=39736&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=39736&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=39736&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=39736&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=39736&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=39736&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=39736&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=39736&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=39736&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=39736&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=39736&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=39736&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=39736&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=39736&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=39736&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=39736&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=39736&r=mysqlcfg

Reply via email to