zlib/bz2: add max_output filter param to cap decompression output#21852
Open
iliaal wants to merge 1 commit intophp:masterfrom
Open
zlib/bz2: add max_output filter param to cap decompression output#21852iliaal wants to merge 1 commit intophp:masterfrom
iliaal wants to merge 1 commit intophp:masterfrom
Conversation
Optional max_output parameter on zlib.inflate and bzip2.decompress caps bytes emitted by the filter. When the instance has a cap set and exceeds it, the current bucket is dropped and the filter returns PSFS_ERR_FATAL, stopping decompression amplification mid-stream instead of after the full payload lands on the sink. The parameter is opt-in. Omitting it preserves existing behavior for all current callers. Userland opts in via stream_filter_append($stream, 'zlib.inflate', STREAM_FILTER_WRITE, ['max_output' => N]).
LamentXU123
reviewed
Apr 24, 2026
| } | ||
|
|
||
| if ((tmpzval = zend_hash_str_find_ind(ht, "max_output", sizeof("max_output")-1))) { | ||
| zend_long tmp = zval_get_long(tmpzval); |
Contributor
There was a problem hiding this comment.
IMO we could use zval_try_get_long, to prevent silent casting of user's input. A previous PR #21841 has done to option strategy in zlib init_deflate but it seems like I've missed the case in other options (windows, etc.) I'll take care of this myself. Anyway, should use zval_try_get_long here to avoid silent casting.
| } | ||
|
|
||
| if ((tmpzval = zend_hash_str_find_ind(ht, "max_output", sizeof("max_output") - 1))) { | ||
| zend_long tmp = zval_get_long(tmpzval); |
Contributor
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.
Adds
max_outputtozlib.inflateandbzip2.decompress. When set, the filter tracks emitted bytes; once the cap is exceeded, the current bucket is dropped and the filter returnsPSFS_ERR_FATAL, halting decompression mid-stream rather than after the full payload lands on the sink.Opt-in on both filters. Omitting the key keeps existing behavior for every current caller. From userland:
stream_filter_append($stream, 'zlib.inflate', STREAM_FILTER_WRITE, ['max_output' => N]).A follow-up PR will wire this into phar so crafted archives with inflated
uncompressed_filesizefail during streaming.