Repository navigation
Fix GH-25903: bzip2.decompress write filter writes past its input buffer after a data error - #25904
Closed
ArtUkrainskiy wants to merge 1 commit into
Closed
ArtUkrainskiy wants to merge 1 commit into
ArtUkrainskiy wants to merge 1 commit into
Conversation
…buffer after a data error On a data error the filter returned before it reset next_in and avail_in. The filter stays on the stream, so the next write copied its input at the advanced next_in, and the copy could go past the end of the 2048-byte input buffer. Reset both before returning, as zlib.inflate does, and raise the notice last, because an error handler can close the stream and free the filter.
ArtUkrainskiy
marked this pull request as ready for review
November 29, 2026 20:34
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.
Fixes GH-25903
When
BZ2_bzDecompress()fails,php_bz2_decompress_filter()returns before it resetsnext_inandavail_in. bzlib has already movednext_inforward. The filter stays on the stream, so the next write copies its input at the advancednext_in, and the copy can go past the end of the 2048-byteinbuf.This resets both before returning, like zlib.inflate does. The notice now goes last, because an error handler can close the stream and free the filter. zlib.inflate got the same order in #24176.
The test writes one byte at a time, so the position moves past the buffer after about 2048 writes. It needs
USE_ZEND_ALLOC=0. With the Zend allocator the overflow doesn't crash. Without the fix it aborts in glibc on a debug build and fails with ASan. ext/bz2 tests pass with ASan and ZTS. The code change applies cleanly to 8.5, 8.6 and master.