Skip to content

content encoding: reject incomplete zlib streams (gzip, deflate) - #23669

Closed
piru wants to merge 4 commits into
curl:masterfrom
piru:check_zlib_stream_end
Closed

piru wants to merge 4 commits into
curl:masterfrom
piru:check_zlib_stream_end

Conversation

@piru

@piru piru commented Oct 29, 2026

Copy link
Copy Markdown

Disallow incomplete zlib streams for deflate and gzip content encoding.

Fixes deflate and gzip issue reported in #23615

@bagder
bagder requested review from icing and a balanced review from Copilot October 29, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Decoder completion checks incorrectly reject valid bodyless HEAD responses advertising deflate, gzip, or x-gzip, causing curl -I --compressed to fail with error 61.

1 open issue
What changed in this PR

This PR tightens libcurl’s gzip and deflate decoding to reject incomplete compressed streams, addressing the zlib-related cases in #23615.

Changes:

  • Track whether decompression reaches Z_STREAM_END.
  • Add end-of-stream flush checks that return CURLE_BAD_CONTENT_ENCODING for incomplete streams.
File Description
lib/​content_encoding.c Track zlib stream completion and validate it when gzip and deflate decoders finish.

Review effort: Balanced

Comment thread lib/content_encoding.c Resolved
…rver responding with 'Content-Encoding: deflate' and empty body)
@piru

piru commented Oct 29, 2026 •

Copy link
Copy Markdown
Author

Revised the code, now it maintains a zlibStreamState (SSTATE_INIT, SSTATE_PROCESSING, SSTATE_ENDED) and then flush can check if the state is SSTATE_PROCESSING at the end of stream. If so, the stream processing is incomplete, and flush will error out.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Regression tests are still needed for truncated gzip and deflate payloads with matching Content-Length to verify error 61 without HTTP length errors masking failures, and for encoded bodyless HEAD responses to protect the SSTATE_INIT exemption.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread lib/content_encoding.c Resolved
…alid/incomplete deflate content failing), 4274 (HEAD response with Content-Encoding: gzip and Content-Lenght: 0 succeeding)
@github-actions github-actions Bot added the tests label Oct 30, 2026
@bagder bagder closed this in 0036b55 Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

4 participants