|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2007-09-13 18:28 UTC] arnaud dot lb at gmail dot com
 Description:
------------
gzinflate() try to allocate all memory with truncated $data:
Fatal error: Out of memory (allocated 1074003968) (tried to allocate 
2147450880 bytes) in Command line code on line 1
Zlib version: 1.2.3.3
Reproduce code:
---------------
/tmp/php-5.2.4$ ./configure --disable-all --enable-cli --with-zlib && make -j4
/tmp/php-5.2.4$ sapi/cli/php -d memory_limit=-1 -r '$data = gzdeflate(file_get_contents("/tmp/yuicompressor-1.0.zip"), 9); echo "Compressed length: " . strlen($data) . "\n"; gzinflate($data); $data = substr($data, 0, 65535); echo "Truncated length: " . strlen($data) . "\n"; gzinflate($data);'
Expected result:
----------------
gzinflate() should return FALSE, without eating all memory
Actual result:
--------------
Fatal error: Out of memory (allocated 1074003968) (tried to allocate 
2147450880 bytes) in Command line code on line 1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 09:00:01 2025 UTC | 
Example code in a more readable format: <?php ini_set('memory_limit', -1); // compressing a ~1.6MB file with gzdeflate() $data = gzdeflate(file_get_contents("/home/noch/yuicompressor-1.0.zip"), 9); echo "Compressed length: " . strlen($data) . "\n"; // gzinflate() works with original $data gzinflate($data); // Truncating compressed $data $data = substr($data, 0, 65535); echo "Truncated length: " . strlen($data) . "\n"; // Bug is here: gzinflate($data); ?>