Skip to content

Commit

Permalink
Fix #81302: Stream position after stream filter removed
Browse files Browse the repository at this point in the history
When flushing the stream filters actually causes data to be written to
the stream, we need to update its position, because that is not done by
the streams' write methods.

Closes GH-7354.
  • Loading branch information
cmb69 committed Aug 10, 2021
1 parent 79d564a commit 40b31fc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.4.24

- Core:
. Fixed bug #81302 (Stream position after stream filter removed). (cmb)

26 Aug 2021, PHP 7.4.23

Expand Down
20 changes: 20 additions & 0 deletions ext/standard/tests/filters/bug81302.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Bug #81302 (Stream position after stream filter removed)
--SKIPIF--
<?php
if (!extension_loaded('zlib')) die("skip zlib extension not available");
?>
--FILE--
<?php
$f = fopen("php://memory", "w+b");
$z = stream_filter_append($f, "zlib.deflate", STREAM_FILTER_WRITE, 6);
fwrite($f, "Testing");
stream_filter_remove($z);
$pos = ftell($f);
fseek($f, 0);
$count = strlen(fread($f, 1024));
fclose($f);
var_dump($count === $pos);
?>
--EXPECT--
bool(true)
5 changes: 4 additions & 1 deletion main/streams/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@ PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish)
} else if (chain == &(stream->writefilters)) {
/* Send flushed data to the stream */
while ((bucket = inp->head)) {
stream->ops->write(stream, bucket->buf, bucket->buflen);
ssize_t count = stream->ops->write(stream, bucket->buf, bucket->buflen);
if (count > 0) {
stream->position += count;
}
php_stream_bucket_unlink(bucket);
php_stream_bucket_delref(bucket);
}
Expand Down

0 comments on commit 40b31fc

Please sign in to comment.