Repository navigation
Raw deflate decoding fails when the first response chunk is one byte #3799
Replies: 3 comments 1 reply
|
Independently reproduced on Linux with Python 3.12.14 and zlib 1.3.1.zlib-ng, using HTTPX master I checked 48 in-memory response cases: raw and zlib-wrapped deflate, empty / 8-byte / 2048-byte bodies, chunk sizes 1 / 2 / 3 / whole stream, synchronous reads and asynchronous reads under asyncio.
This adds a Linux/zlib-ng check to your macOS results and confirms the behavior is not tied to a live HTTP server. I have not run the full HTTPX suite or Trio in this environment, so this is focused reproduction evidence rather than full approval of the patch. |
|
Additional verification at master The review commit with extra tests credits @widechaos's original With this decoder change and the PATH_INFO candidate from #3798 applied together, the final full suite passed 1478 tests, 1 skipped on Linux/Python 3.12.14. An earlier run hit I can contribute this additional coverage to the proposed fix. |
Uh oh!
There was an error while loading. Please reload this page.
A raw-deflate response decodes correctly when supplied as one chunk, but raises
DecodingErrorwhen the first chunk contains just one byte. I reproduced this on current master (b5addb64f0161ff6bfe94c124ef76f6a1fba5254).The raw-deflate fallback is already supported by
DeflateDecoder. With a one-byte first chunk, zlib has not seen enough input to reject the header, butfirst_attemptis set toFalse. The second chunk then raises without trying the raw decoder. This also reproduces withResponse.aread(), under both asyncio and Trio; no server or network request is needed.I prepared a small candidate fix and regression tests: retain the initial byte until both header bytes are available, then keep the existing fallback. Tests cover raw deflate and zlib-wrapped deflate with small synchronous chunks and one-byte async chunks.
The decoder tests, formatting, typing and lint checks pass. The full suite has one existing
test_write_timeout[trio]resource-warning failure, which I also reproduced with the original decoder. Excluding that single test leaves 1424 passed and 1 skipped.Environment: macOS 26.6.2 arm64, Python 3.13.15, HTTPX 0.28.1 checkout, zlib 1.2.12.
Is this approach suitable for a PR? I'm raising it here first as requested by the contribution guide.
All reactions