Bug #81302 [NEW]: Stream position after stream filter removed

From: Date: Tue, 27 Jul 2021 09:46:10 +0000
Subject: Bug #81302 [NEW]: Stream position after stream filter removed
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235391@lists.php.net to get a copy of this message
From:             ivo dot andonov at gmail dot com
Operating system: Linux / Windows
PHP version:      8.0.8
Package:          Streams related
Bug Type:         Bug
Bug description:Stream position after stream filter removed

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


Thread (5 messages)

« previous php.bugs (#235391) next »