Repository navigation
Check the second gzip magic byte in JdkZlibDecoder - #17972
Merged
Merged
Conversation
Motivation: JdkZlibDecoder reads both gzip magic bytes (ID1 = 0x1f, ID2 = 0x8b, RFC 1952 section 2.3.1) but only checks the first one, so a stream with a wrong ID2 is decoded as gzip. java.util.zip.GZIPInputStream and JdkZlibDecompressor reject such a stream. Modifications: - Read both bytes unsigned and check ID2 as JdkZlibDecompressor does. - Add a test. Result: JdkZlibDecoder rejects input whose gzip header has a wrong ID2.
✅ All tests passed ✅🏷️ Commit: fd8f851 Learn more about TestLens at testlens.app/docs. |
Contributor
|
Could not create auto-port PR. |
Contributor
|
Auto-port PR for 5.0: #18006 |
Member
|
Port for 4.1. #18007 |
normanmaurer
added a commit
that referenced
this pull request
Oct 22, 2026
…8006) 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. Co-authored-by: Martin Mirchev <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
normanmaurer
added a commit
that referenced
this pull request
Oct 22, 2026
…#18007) 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`.
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`.
5 tasks done
hyperxpro
pushed a commit
to AsyncHttpClient/async-http-client
that referenced
this pull request
Nov 6, 2026
## Summary - Upgrades Netty from 4.2.19.Final to 4.2.20.Final. Its [security fixes](https://github.com/netty/netty/releases/tag/netty-4.2.20.Final) include several in modules AHC uses: three out-of-bounds reads in `netty-buffer`, unbounded memory usage in `netty-codec-http2`, insufficient control character neutralization in `netty-codec-http`, insufficient entropy in `netty-resolver-dns`, and an mTLS bypass via session resumption in `netty-handler`. - On 4.2.20, two of AHC's tests fail, both because of Netty changes. This PR adapts AHC to them. ## Change - **Upgrade Netty to 4.2.20.Final, and check the second gzip magic byte:** `JdkZlibDecoder` now rejects a gzip header with a wrong second magic byte (netty/netty#17972). The gzip inflate loop from #2357 follows `JdkZlibDecoder`, and `Http1ContentDecompressorTest` compares the two, so it now checks that byte too. Both bytes are read unsigned, since `0x8b` is negative as a signed byte. - **Keep zstd working at a non-positive threshold:** since netty/netty#17896, the `ZstdDecoder` that `HttpContentDecompressor` creates sizes its output buffers by `io.netty.compression.defaultMaxForwardBytes`. At 0 it hands on an empty body without an error; below 0 it fails with `IllegalArgumentException: initialCapacity : -1`. AHC leaves zstd to that decoder while the property is not positive (#2362), so it now replaces it with a `ZstdDecoder` whose buffers hold `MAX_PART_SIZE`. The size limit still applies, and the body is still decompressed eagerly there, as before. At the default value of the property nothing changes. netty/netty#18289 fixes the decoder in Netty; this workaround is harmless with that fix and can go once AHC requires a Netty version that has it. ## Notes - Netty 4.2.0 to 4.2.4 have no `ZstdDecoder(int)` constructor. Overriding AHC's Netty with one of those and also setting the property to 0 or below would fail zstd responses with a `NoSuchMethodError`. ## AI disclosure Claude Code on behalf of Matthias Kurz. Both commits include `Co-Authored-By` per `AGENTS.md`. ## Test plan - [x] `main` at `5542c9fc4` with `-Dnetty.version=4.2.20.Final`: 1,857 tests, 2 failures: - `Http1ContentDecompressorTest.decodesLikeNettyForEveryBodyAndSplit`, case "gzip second magic byte ignored": Netty now fails that body, AHC did not. - `Http1ContentDecompressorForwardThresholdTest`: "the zstd body differs". - [x] `Http1ContentDecompressorForwardThresholdTest` now runs at thresholds 0 and -1, each in a fresh JVM, and also checks the size limit for zstd and that every exchange releases its input and buffers. On 4.2.20 without the zstd commit it fails at both ("the zstd body differs", "the zstd body did not end"). With it, it passes on 4.2.19 and 4.2.20. - [x] `./mvnw -B -ntp -Dgpg.skip=true clean verify` on JDK 11, on `main` `3e95ec8c2`: 1,905 tests, 0 failures, 0 errors, 11 skipped; Revapi passed. No test-skipping flags were used. - [x] `Http1ContentDecompressorForwardThresholdTest` and `Http1ContentDecompressorTest` compiled on JDK 11 and run on JDK 17, 21 and 25 (Maven Surefire's `-Djvm`): 36 tests each, 0 failures. - [x] This branch merged with #2369: `clean verify` on JDK 11, 1,914 tests, 0 failures, 0 errors, 11 skipped; Revapi passed (run before #2359, #2360 and #2361 were merged, with those three merged in as well). --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
ikpil
added a commit
to ikpil/Netty.NET
that referenced
this pull request
Nov 29, 2026
…netty#17972) 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
JdkZlibDecoderreads 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.GZIPInputStreamand netty's ownJdkZlibDecompressor(magic0 != 31 || magic1 != 139) reject such a stream.Modification:
JdkZlibDecompressordoes.JdkZlibTest.testGzipInvalidSecondMagicByteThrows.Result:
JdkZlibDecoderrejects input whose gzip header has a wrong ID2.Reproduction on 4.2 (5776ebc): compress
"hello gzip"withGZIPOutputStreamand set byte 1 to0x00:With this change
JdkZlibDecoderthrowsDecompressionException: Input is not in the GZIP format. The new test fails without the change (no exception is thrown). The*Zlib*Testtests incodec-compressionpass.This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.
🤖 Generated with Claude Code