Commit 2396a0c1224 for php
commit 2396a0c122436ae3a82247c05264d0fae09f1b9d
Author: Artem Ukrainskiy <art.ukrainskiy@gmail.com>
Date: Mon Nov 30 16:58:01 2026 +0000
ext/standard: "consumed" stream filter loses or repeats data
On its final flush, at the end of the stream or on stream_filter_remove(),
the filter seeked the stream it is attached to. In 8.4 and 8.5 this lost
the data: reading a whole file through the filter returned an empty string.
Since 8.6 the seek is rejected with a warning. When the first chunk already
ends the stream, the seek goes to the start: it rewinds the stream and
resets the filter, so the data is read again, and with two consumed filters
the read never ends.
Remove the seek. The filter now passes the data through unchanged.
Fixes GH-25959
Closes GH-25966
diff --git a/NEWS b/NEWS
index 4df9054c3e4..7b35ee47b1a 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.4.30
+- Standard:
+ . Fixed bug GH-25959 ("consumed" stream filter loses or repeats data).
+ (Artem Ukrainskiy)
+
17 Dec 2026, PHP 8.4.29
diff --git a/ext/standard/filters.c b/ext/standard/filters.c
index 3c6cfd84af0..c2042f5d90e 100644
--- a/ext/standard/filters.c
+++ b/ext/standard/filters.c
@@ -1635,9 +1635,6 @@ static php_stream_filter_status_t consumed_filter_filter(
if (bytes_consumed) {
*bytes_consumed = consumed;
}
- if (flags & PSFS_FLAG_FLUSH_CLOSE) {
- php_stream_seek(stream, data->offset + data->consumed, SEEK_SET);
- }
data->consumed += consumed;
return PSFS_PASS_ON;
diff --git a/ext/standard/tests/filters/gh25959.phpt b/ext/standard/tests/filters/gh25959.phpt
new file mode 100644
index 00000000000..6330baffb63
--- /dev/null
+++ b/ext/standard/tests/filters/gh25959.phpt
@@ -0,0 +1,51 @@
+--TEST--
+GH-25959 ("consumed" stream filter loses or repeats data)
+--FILE--
+<?php
+var_dump(file_get_contents('php://filter/read=consumed/resource=data:,ab'));
+var_dump(file_get_contents('php://filter/read=consumed|consumed/resource=data:,ab'));
+
+$name = __DIR__ . '/gh25959.tmp';
+file_put_contents($name, "l1\nl2\nl3\n");
+
+$f = fopen($name, 'r');
+stream_filter_append($f, 'consumed');
+var_dump(stream_get_contents($f));
+fclose($f);
+
+$f = fopen($name, 'r');
+stream_filter_append($f, 'consumed');
+while (($line = fgets($f)) !== false) {
+ var_dump($line);
+}
+fclose($f);
+
+$f = fopen($name, 'r');
+$filter = stream_filter_append($f, 'consumed');
+var_dump(fread($f, 3));
+stream_filter_remove($filter);
+var_dump(stream_get_contents($f));
+fclose($f);
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/gh25959.tmp');
+?>
+--EXPECT--
+string(2) "ab"
+string(2) "ab"
+string(9) "l1
+l2
+l3
+"
+string(3) "l1
+"
+string(3) "l2
+"
+string(3) "l3
+"
+string(3) "l1
+"
+string(6) "l2
+l3
+"