GzipDecompressor: decompress concatenated gzip members instead of dropping them#3654
Open
HrachShah wants to merge 2 commits into
Open
GzipDecompressor: decompress concatenated gzip members instead of dropping them#3654HrachShah wants to merge 2 commits into
HrachShah wants to merge 2 commits into
Conversation
added 2 commits
June 26, 2026 15:38
…pping them Issue tornadoweb#3560. The previous implementation called zlib.decompressobj.decompress once per chunk and returned whatever the inner decompressor produced. When the wrapped HTTP response contains two or more gzip members in sequence (some servers split a gzipped response across members for obfuscation or to defeat naive transport encoders), the inner decompressor reached EOF on the first member and declared itself complete. Any bytes past the first trailer sat in the inner unused_data and were never read, so the second member and every member after it were silently dropped on the floor. Rework GzipDecompressor so callers that pass max_length=0 (the default, and the only mode used by HTTP1Connection) transparently advance across consecutive members: after each member finishes, any leftover bytes in the inner decompressobj's unused_data are folded back into the input and a fresh zlib.decompressobj is wired up for the next member. The public unconsumed_tail property continues to report what a caller should re-feed on the next call (now backed by an explicit _pending buffer combined with the inner tail). When max_length is non-zero the single-call behaviour callers depend on is preserved and unused_data is staged in _pending for the next call. flush advances across all remaining members as well. Added GzipDecompressorTest covering a single member (baseline), two concatenated members fed in one decompress call, and four members split across alternating decompress calls to exercise the between-call buffering path.
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.
Issue #3560.
tornado.util.GzipDecompressorwas silently dropping every gzip member after the first one.zlib.decompressobjreports end-of-member viaeofand the leftover bytes (which belong to the next member) viaunused_data; the previous implementation never inspected either, so a response body that was gzipped in chunks was truncated to the first chunk's worth of data.decompressnow keeps a small_pendingbuffer, swaps in a fresh inner decompressor when the current member ends, and feeds it any bytes that arrived past the previous member's trailer. When called with nomax_lengthcap the inner loop drains across all consecutive members transparently; when called with a cap, the trailing bytes of the current call are staged in_pendingfor the next call so the caller can still drive the stream viaunconsumed_tail.flushwalks every remaining member and concatenates their output into the returned bytes.unconsumed_tailis the sum of_pendingand the inner object'sunconsumed_tail.Added
GzipDecompressorTestintornado/test/util_test.pycovering: a single member (sanity), three members concatenated in onedecompresscall, and four members split across manydecompresscalls (the buffering path).