php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74240 deflate_add can allocate too much memory
Submitted: 2017-03-13 03:43 UTC Modified: -
From: matt at bonneau dot net Assigned:
Status: Closed Package: Zlib related
PHP Version: master-Git-2017-03-13 (Git) OS: All
Private report: No CVE-ID: None
 [2017-03-13 03:43 UTC] matt at bonneau dot net
Description:
------------
deflate_add can grossly overestimate memory needed for the output buffer. This is more likely with highly compressable data. The allocations are roughly equal to the total bytes processed by deflate_add and can cause PHP to run out of memory.

Test script:
---------------
$deflator = deflate_init(ZLIB_ENCODING_RAW);

$bytes = str_repeat("*", 65536);
// if you use random bytes this usually can run forever
// because they are not very compressable
//$bytes = openssl_random_pseudo_bytes(65536);

// this crashes after about 500 iterations if PHP is
// configured for 64M
for ($i = 0; $i < 100000; $i++) {
    echo "$i\n";
    $output = deflate_add(
        $deflator,
        $bytes,
        ZLIB_SYNC_FLUSH
    );
}


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-14 23:08 UTC] bwoebi@php.net
Automatic comment on behalf of matt@bonneau.net
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7fba8bda4c9e89c522e5d27a38489125e36b9904
Log: Fixed bug #74240 (deflate_add can allocate too much memory)
 [2017-03-14 23:08 UTC] bwoebi@php.net
-Status: Open +Status: Closed
 [2017-03-14 23:09 UTC] bwoebi@php.net
Automatic comment on behalf of matt@bonneau.net
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7fba8bda4c9e89c522e5d27a38489125e36b9904
Log: Fixed bug #74240 (deflate_add can allocate too much memory)
 [2017-03-14 23:10 UTC] bwoebi@php.net
Automatic comment on behalf of matt@bonneau.net
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7fba8bda4c9e89c522e5d27a38489125e36b9904
Log: Fixed bug #74240 (deflate_add can allocate too much memory)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC