Bug #80384 [NEW]: zlib.inflate filter buffers entire read until file closed

From: Date: Fri, 20 Nov 2020 04:14:52 +0000
Subject: Bug #80384 [NEW]: zlib.inflate filter buffers entire read until file closed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230468@lists.php.net to get a copy of this message
From:             adamjseitz at gmail dot com
Operating system: Debian Buster on WSL2
PHP version:      7.4.12
Package:          Zlib related
Bug Type:         Bug
Bug description:zlib.inflate filter buffers entire read until file closed

Description:
------------
"zlib.inflate" filters appear to buffer all previously-read data, as
exhibited by the attached code, until the file is closed.

It is unclear from my testing if the data being kept in memory is the
original or inflated copy.

Test script:
---------------
<?php
// Generate "data.gz" file with:
// dd if=/dev/urandom of=data count=$((8*1024*1024)) iflag=count_bytes;
gzip data

function PrintMem($message) { echo $message, ": ", (memory_get_usage() /
1024 / 1024) . " MB\n"; }

$fp = fopen("data.gz", 'rb');
$filter = stream_filter_append($fp, "zlib.inflate", STREAM_FILTER_READ,
array( 'window' => 31 ));

PrintMem("before read");
stream_get_contents($fp);
PrintMem("after read");

stream_filter_remove($filter);
fclose($fp);
PrintMem("after close");
?>

Expected result:
----------------
I expect that very little memory is used.

It should be possible to read smaller blocks at a time from a very large
gzipped files without buffering the entire content of what has been read
so far, but that does not seem to be the case.

Actual result:
--------------
OUTPUT from the above script:

before read: 0.44554138183594 MB
after read: 8.4377517700195 MB
after close: 0.37459564208984 MB

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80384&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80384&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80384&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80384&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80384&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80384&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80384&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80384&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80384&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80384&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80384&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80384&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80384&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80384&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80384&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80384&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80384&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80384&r=mysqlcfg


Thread (5 messages)

« previous php.bugs (#230468) next »