DeflateBuffer: skip RFC 1950 header sniff on empty chunks#13050
Open
HrachShah wants to merge 2 commits into
Open
DeflateBuffer: skip RFC 1950 header sniff on empty chunks#13050HrachShah wants to merge 2 commits into
HrachShah wants to merge 2 commits into
Conversation
feed_data(b"") is used by the chunked-transfer decoder to resume a paused stream (see HttpRequestParser._post_parse and HttpResponseParser around the eof/length branches). When a deflate stream had not yet started decoding, the very first such resume would read chunk[0] to sniff the CM bits of the zlib header and raise IndexError on the empty input. Issue aio-libs#12994. Guard the sniff with a leading truthy check on chunk so an empty chunk falls through to decompress_sync(b""), which is a no-op and returns the same data_available flag the caller's resume loop already uses to decide whether to retry. No exception, no spurious bytes pushed downstream, no infinite loop. Add test_empty_chunk_is_noop covering the pre-decode IndexError case plus a follow-up real-data round-trip to prove the decoder is still usable afterwards. Add CHANGES/12994.bugfix.rst.
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #13050 +/- ##
=======================================
Coverage 98.96% 98.96%
=======================================
Files 131 131
Lines 48156 48170 +14
Branches 2499 2500 +1
=======================================
+ Hits 47656 47670 +14
Misses 376 376
Partials 124 124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
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 #12994.
DeflateBuffer.feed_data(b"")raisedIndexErrorbecause the CM-byte sniff at the start of the method readchunk[0]on the empty input. The chunked-transfer decoder uses emptyfeed_datacalls to resume a paused decompressor (seeHttpRequestParser._post_parseandHttpResponseParseraround the eof/length branches), and on a deflate stream that had not yet started decoding, the very first such resume hit the empty-chunk branch and crashed.Guard the CM-byte sniff with a leading truthy check on
chunkso an empty chunk falls through todecompress_sync(b""), which is already a no-op. The resume loop'sself.decompressor.data_availableflag still drives termination, so no infinite loop is introduced.python3 -m pytest tests/test_http_parser.py -k deflatepasses 88 tests (was 87); the newtest_empty_chunk_is_noopregression test fails on the pre-fix code and passes with the fix.