Bug #81302 [Asn->Ver]: Stream position after stream filter removed
| From: | cmb@php.net | Date: | Tue, 10 Aug 2021 10:01:38 +0000 |
| Subject: | Bug #81302 [Asn->Ver]: Stream position after stream filter removed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235722@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81302&edit=1
ID: 81302
Updated by: cmb@php.net
Reported by: ivo dot andonov at gmail dot com
Summary: Stream position after stream filter removed
-Status: Assigned
+Status: Verified
Type: Bug
Package: Streams related
Operating System: Linux / Windows
PHP Version: 8.0.8
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> fopen("php://memory", "wb");
By the way, the mode should be "w+b" here (or just "w+"), because
reading from a write only stream shouldn't be supported
(apparently it is for memory streams, though).
Previous Comments:
------------------------------------------------------------------------
[2021-08-10 09:57:01] cmb@php.net
The following pull request has been associated:
Patch Name: Fix #81302: Stream position after stream filter removed
On GitHub: https://github.com/php/php-src/pull/7354
Patch: https://github.com/php/php-src/pull/7354.patch
------------------------------------------------------------------------
[2021-07-27 09:46:10] ivo dot andonov at gmail dot com
Description:
------------
This one is somewhat following https://bugs.php.net/bug.php?id=81294 and is again
related to the removal of a filter. If the filter being removed outputs additional data then this
data is correctly written to the underlying stream however the stream position is not updated.
Seems that this should be done here:
https://github.com/php/php-src/blob/PHP-8.0.8/main/streams/filter.c#L471
Or instead of using
stream->ops->write(stream, bucket->buf, bucket->buflen);
probably call (speculating) https://github.com/php/php-src/blob/PHP-8.0.8/main/streams/streams.c#L1120
Test script:
---------------
<?
$f = fopen("php://memory", "wb");
$z = stream_filter_append($f, "zlib.deflate", STREAM_FILTER_WRITE, 6);
fwrite($f, "Test");
stream_filter_remove($z);
echo "Position after remove: " . ftell($f) . "\n"; // 0 reported, should be 6
echo "Read: " . strlen(fread($f, 1024)) . "\n"; // 0 bytes
fseek($f, 0);
echo "Read after seek to the beginning: " . strlen(fread($f, 1024)) . "\n"; //
6 bytes read, so ftell should have reported 6
fclose($f);
?>
Expected result:
----------------
After a filter is removed if it outputs additional data the underlying stream position (ftell)
should be updated accordingly.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81302&edit=1