Skip to content

Port 4.1: Check the second gzip magic byte in JdkZlibDecoder (#17972) - #18007

Merged
normanmaurer merged 1 commit into
4.1from
smart-thunder-e859c150
Oct 22, 2026
Merged

normanmaurer merged 1 commit into
4.1from
smart-thunder-e859c150

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Auto-port of #17972 to 4.1
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:

A gzip stream with an invalid ID2 byte is rejected with a
DecompressionException.

Auto-port of #17972 to 4.1
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:

A gzip stream with an invalid ID2 byte is rejected with a
`DecompressionException`.
@normanmaurer normanmaurer added this to the 4.1.140.Final milestone Oct 22, 2026
@normanmaurer
normanmaurer merged commit 704fbc9 into 4.1 Oct 22, 2026
19 checks passed
@normanmaurer
normanmaurer deleted the smart-thunder-e859c150 branch October 22, 2026 17:21
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…7972) (netty#18007)

Auto-port of netty#17972 to 4.1
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:

A gzip stream with an invalid ID2 byte is rejected with a
`DecompressionException`.
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.

1 participant