|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81302 Stream position after stream filter removed
Submitted: 2021-07-27 09:46 UTC Modified: 2021-08-10 10:01 UTC
From: ivo dot andonov at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Streams related
PHP Version: 8.0.8 OS: Linux / Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: ivo dot andonov at gmail dot com
New email:
PHP Version: OS:


 [2021-07-27 09:46 UTC] ivo dot andonov at gmail dot com
This one is somewhat following 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:

Or instead of using 

stream->ops->write(stream, bucket->buf, bucket->buflen);

probably call (speculating)

Test script:
  $f = fopen("php://memory", "wb");
  $z = stream_filter_append($f, "zlib.deflate", STREAM_FILTER_WRITE, 6);
  fwrite($f, "Test");
  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

Expected result:
After a filter is removed if it outputs additional data the underlying stream position (ftell) should be updated accordingly.


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-27 11:50 UTC]
-Assigned To: +Assigned To: cmb
 [2021-07-27 11:50 UTC]
-Status: Assigned +Status: Open
 [2021-08-10 09:57 UTC]
The following pull request has been associated:

Patch Name: Fix #81302: Stream position after stream filter removed
On GitHub:
 [2021-08-10 10:01 UTC]
-Status: Assigned +Status: Verified
 [2021-08-10 10:01 UTC]
> 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).
 [2021-08-10 14:42 UTC]
Automatic comment on behalf of cmb69
Log: Fix #81302: Stream position after stream filter removed
 [2021-08-10 14:42 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 17:01:34 2024 UTC