Skip to content

Auto-port 5.0: Check the second gzip magic byte in JdkZlibDecoder - #18006

Merged
normanmaurer merged 1 commit into
5.0from
auto-port-pr-17972-to-5.0
Oct 22, 2026
Merged

normanmaurer merged 1 commit into
5.0from
auto-port-pr-17972-to-5.0

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #17972 to 5.0
Cherry-picked commit: f69f14a


Motivation:

JdkZlibDecoder reads both gzip magic bytes (ID1 = 0x1f, ID2 = 0x8b, RFC 1952 section 2.3.1) but only checks ID1, so a stream with a wrong ID2 is decoded as gzip. java.util.zip.GZIPInputStream and netty's own JdkZlibDecompressor (magic0 != 31 || magic1 != 139) reject such a stream.

Modification:

  • Read both bytes unsigned and check ID2, as JdkZlibDecompressor does.
  • Add JdkZlibTest.testGzipInvalidSecondMagicByteThrows.

Result:

JdkZlibDecoder rejects input whose gzip header has a wrong ID2.

Reproduction on 4.2 (5776ebc): compress "hello gzip" with GZIPOutputStream and set byte 1 to 0x00:

JDK GZIPInputStream: rejected (Not in GZIP format)
netty JdkZlibDecoder(GZIP): accepted, output = [hello gzip]

With this change JdkZlibDecoder throws DecompressionException: Input is not in the GZIP format. The new test fails without the change (no exception is thrown). The *Zlib*Test tests in codec-compression pass.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.

🤖 Generated with Claude Code

Motivation:

`JdkZlibDecoder` reads both gzip magic bytes (ID1 = 0x1f, ID2 = 0x8b,
RFC 1952 section 2.3.1) but only checks ID1, so a stream with a wrong
ID2 is decoded as gzip. `java.util.zip.GZIPInputStream` and netty's own
`JdkZlibDecompressor` (`magic0 != 31 || magic1 != 139`) reject such a
stream.

Modification:

- Read both bytes unsigned and check ID2, as `JdkZlibDecompressor` does.
- Add `JdkZlibTest.testGzipInvalidSecondMagicByteThrows`.

Result:

`JdkZlibDecoder` rejects input whose gzip header has a wrong ID2.

Co-authored-by: Norman Maurer <[email protected]>
(cherry picked from commit f69f14a)
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Oct 22, 2026
@normanmaurer
normanmaurer merged commit 979e9f3 into 5.0 Oct 22, 2026
14 checks passed
@normanmaurer
normanmaurer deleted the auto-port-pr-17972-to-5.0 branch October 22, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants