Skip to content

DeflateBuffer: skip RFC 1950 header sniff on empty chunks#13050

Open
HrachShah wants to merge 2 commits into
aio-libs:masterfrom
HrachShah:fix-12994-deflate-empty-chunk
Open

DeflateBuffer: skip RFC 1950 header sniff on empty chunks#13050
HrachShah wants to merge 2 commits into
aio-libs:masterfrom
HrachShah:fix-12994-deflate-empty-chunk

Conversation

@HrachShah

Copy link
Copy Markdown

Fixes #12994.

DeflateBuffer.feed_data(b"") raised IndexError because the CM-byte sniff at the start of the method read chunk[0] on the empty input. The chunked-transfer decoder uses empty feed_data calls to resume a paused decompressor (see HttpRequestParser._post_parse and HttpResponseParser around 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 chunk so an empty chunk falls through to decompress_sync(b""), which is already a no-op. The resume loop's self.decompressor.data_available flag still drives termination, so no infinite loop is introduced.

python3 -m pytest tests/test_http_parser.py -k deflate passes 88 tests (was 87); the new test_empty_chunk_is_noop regression test fails on the pre-fix code and passes with the fix.

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.
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jul 4, 2026
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.96%. Comparing base (e3774b4) to head (0b89ab2).
✅ All tests successful. No failed tests found.

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           
Flag Coverage Δ
Autobahn 22.21% <7.14%> (-0.01%) ⬇️
CI-GHA 98.90% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.66% <100.00%> (-0.01%) ⬇️
OS-Windows 97.04% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.95% <100.00%> (+<0.01%) ⬆️
Py-3.10 98.14% <100.00%> (-0.01%) ⬇️
Py-3.11 98.41% <100.00%> (+<0.01%) ⬆️
Py-3.12 98.50% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.47% <100.00%> (+<0.01%) ⬆️
Py-3.14 98.49% <100.00%> (+<0.01%) ⬆️
Py-3.14t 97.58% <100.00%> (-0.01%) ⬇️
Py-pypy-3.11 97.44% <100.00%> (+<0.01%) ⬆️
VM-macos 97.95% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.66% <100.00%> (-0.01%) ⬇️
VM-windows 97.04% <100.00%> (+<0.01%) ⬆️
cython-coverage 38.13% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@codspeed-hq

codspeed-hq Bot commented Jul 4, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 83 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing HrachShah:fix-12994-deflate-empty-chunk (0b89ab2) with master (e3774b4)

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeflateBuffer.feed_data raises IndexError on empty chunks

1 participant