Bug #81092 [NEW]: Calling fflush before stream_filter_remove results in corrupted stream
| From: | mark at klb dot jp | Date: | Mon, 31 May 2021 18:34:32 +0000 |
| Subject: | Bug #81092 [NEW]: Calling fflush before stream_filter_remove results in corrupted stream | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-234127@lists.php.net to get a copy of this message | ||
From: mark at klb dot jp
Operating system: Linux
PHP version: 8.0.6
Package: Bzip2 Related
Bug Type: Bug
Bug description:Calling fflush before stream_filter_remove results in corrupted stream
Description:
------------
When using filters to output bzip2 compressed data, one may be tempted
to call fflush() before stream_filter_remove() to ensure all data has
been written.
This used to work fine, however since php8, this causes the generated
stream to be corrupt.
Test script:
---------------
<?php
if ($_SERVER['argv'][1]??'' == 'output') {
$stream = fopen('php://output', 'wb+');
$filter = stream_filter_append($stream, 'bzip2.compress',
STREAM_FILTER_WRITE, ['blocks' => 9, 'work' => 0]);
fwrite($stream, random_bytes(8192));
fflush($stream);
stream_filter_remove($filter); // should call dtor
exit;
}
$script = $_SERVER['argv'][0];
$res = shell_exec('php '.escapeshellarg($script).' output'); // should
output bz encoded data
$data = bzdecompress($res);
var_dump(strlen($data));
Expected result:
----------------
int(8192)
Actual result:
--------------
int(0)
--
Edit bug report at https://bugs.php.net/bug.php?id=81092&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81092&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81092&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81092&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81092&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81092&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81092&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81092&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81092&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81092&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81092&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81092&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81092&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81092&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81092&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81092&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81092&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81092&r=mysqlcfg