Skip to content

Fix GH-25959: "consumed" stream filter loses or repeats data - #25966

Open
ArtUkrainskiy wants to merge 1 commit into
php:PHP-8.4from
ArtUkrainskiy:consumed-filter-no-seek
Open

ArtUkrainskiy wants to merge 1 commit into
php:PHP-8.4from
ArtUkrainskiy:consumed-filter-no-seek

Conversation

@ArtUkrainskiy

Copy link
Copy Markdown
Contributor

Fixes GH-25959

On its final flush, consumed_filter_filter() seeks the stream it's attached to. That happens when a read reaches the end of the stream, or on stream_filter_remove(). In 8.4 and 8.5 the data is lost. stream_get_contents() on a file through the filter returns an empty string, and fgets() returns no lines. Since 8.6 the seek is rejected with a warning. When the first chunk already ends the stream, the seek goes to the start, and the data comes back twice. With two consumed filters that read never ends.

The seek has been there since the filter was added in 2006, and the filter has no tests or docs. I couldn't find a case where the seek does something useful, so this removes it. The filter now passes the data through unchanged.

The test fails without the fix on 8.4 and on 8.6. Stream, filter and file tests pass on 8.4 and 8.6, and the test passes with ASan and ZTS. The code change applies cleanly to 8.5, 8.6 and master.

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.
@ArtUkrainskiy
ArtUkrainskiy marked this pull request as ready for review December 1, 2026 02:40
@ArtUkrainskiy
ArtUkrainskiy requested a review from bukka as a code owner December 1, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant