Skip to content

Commit 2e71c94

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #81302: Stream position after stream filter removed
2 parents 00bb7c9 + 40b31fc commit 2e71c94

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2021, PHP 8.0.11
44

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

68
26 Aug 2021, PHP 8.0.10
79

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #81302 (Stream position after stream filter removed)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('zlib')) die("skip zlib extension not available");
6+
?>
7+
--FILE--
8+
<?php
9+
$f = fopen("php://memory", "w+b");
10+
$z = stream_filter_append($f, "zlib.deflate", STREAM_FILTER_WRITE, 6);
11+
fwrite($f, "Testing");
12+
stream_filter_remove($z);
13+
$pos = ftell($f);
14+
fseek($f, 0);
15+
$count = strlen(fread($f, 1024));
16+
fclose($f);
17+
var_dump($count === $pos);
18+
?>
19+
--EXPECT--
20+
bool(true)

main/streams/filter.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,10 @@ PHPAPI int _php_stream_filter_flush(php_stream_filter *filter, int finish)
468468
} else if (chain == &(stream->writefilters)) {
469469
/* Send flushed data to the stream */
470470
while ((bucket = inp->head)) {
471-
stream->ops->write(stream, bucket->buf, bucket->buflen);
471+
ssize_t count = stream->ops->write(stream, bucket->buf, bucket->buflen);
472+
if (count > 0) {
473+
stream->position += count;
474+
}
472475
php_stream_bucket_unlink(bucket);
473476
php_stream_bucket_delref(bucket);
474477
}

0 commit comments

Comments
 (0)