Discard buckets abandoned by a filter that returns no output - #304
Closed
iliaal wants to merge 1 commit into
Closed
Conversation
A user filter can append to its $out brigade and still answer PSFS_FEED_ME or PSFS_ERR_FATAL. _php_stream_filter_flush() returned without touching either brigade, and _php_stream_write_filtered() drained only brig_inp, so those buckets leaked with bucket->brigade still pointing at the caller's stack frame; re-appending such a bucket later writes through it. php_stream_fill_read_buffer() and php_stream_filter_append_ex() already discard them. Closes phpGH-23564
iliaal
force-pushed
the
fix/filter-brigade-drain-84
branch
from
September 4, 2026 12:15
905c28e to
a844281
Compare
Owner
Author
|
Promoted upstream as php#23564. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A user stream filter can append buckets to its
$outbrigade and still answerPSFS_FEED_MEorPSFS_ERR_FATAL. Two of the four call sites that dispatch a filter never discard those buckets:_php_stream_filter_flush()returns on both statuses without touching either brigade, and_php_stream_write_filtered()drains onlybrig_inp, which is the brigade the filter consumed from rather than the one it appended to.php_stream_fill_read_buffer()andphp_stream_filter_append_ex()already drain the output brigade on the same statuses, so this is a gap in two of four siblings rather than a design choice.Every brigade involved is a local on the dispatching frame, and
php_stream_bucket_unlink()is the only thing that clearsbucket->brigade. An abandoned bucket therefore keeps a pointer into a frame that has returned. If a filter also holds theStreamBucketobject in a property, so the bucket is never freed, re-appending it on a later call reachesphp_stream_bucket_attach()and unlinks through that stale pointer. ASAN reportsstack-use-after-returninphp_stream_bucket_unlink()for that shape. It needs the ability to author thefilter()method, so it is a correctness bug rather than a security issue.Both tests fail on an unfixed debug build (6 and 2 leaks) and pass with the fix.
ext/standard/tests/filtersis green on PHP-8.4; the one failure inext/standard/tests/streamsisbug76136.phpt, which fails identically on an unpatched tree here.