GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Check the second gzip magic byte in JdkZlibDecoder by Marti2203 · Pull Request #17972 · netty/netty

Conversation

@Marti2203

@Marti2203 Marti2203 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Marti2203
Check the second gzip magic byte in JdkZlibDecoder
549f2ff
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.
@normanmaurer normanmaurer added this to the 4.2.20.Final milestone Oct 21, 2026
@normanmaurer normanmaurer added needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Oct 21, 2026
@normanmaurer
Merge branch '4.2' into jdkzlib-gzip-id2
fd8f851
@testlens-app

testlens-app Bot commented Oct 21, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: fd8f851
▶️ Tests: 44389 executed
⚪️ Checks: 26/26 completed


Learn more about TestLens at testlens.app/docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer
normanmaurer merged commit f69f14a into netty:4.2 Oct 22, 2026
27 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot

netty-project-bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 4.1.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot netty-project-bot mentioned this pull request Oct 22, 2026
Auto-port 5.0: Check the second gzip magic byte in JdkZlibDecoder #18006
Merged
@netty-project-bot

netty-project-bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #18006

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Oct 22, 2026
@normanmaurer normanmaurer mentioned this pull request Oct 22, 2026
Port 4.1: Check the second gzip magic byte in JdkZlibDecoder (#17972) #18007
Merged
@normanmaurer normanmaurer removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Oct 22, 2026
@normanmaurer

normanmaurer commented Oct 22, 2026

Copy link
Copy Markdown
Member

Port for 4.1. #18007

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Marti2203 Marti2203 mentioned this pull request Oct 22, 2026
Check the second gzip magic byte in JdkZlibDecoder #18011
Closed
normanmaurer added a commit that referenced this pull request Oct 22, 2026
@netty-project-bot @Marti2203 @normanmaurer
Auto-port 5.0: Check the second gzip magic byte in JdkZlibDecoder (#1…
979e9f3
…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
@normanmaurer
Port 4.1: Check the second gzip magic byte in JdkZlibDecoder (#17972) (…
704fbc9
…#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
@normanmaurer @lltopk
Port 4.1: Check the second gzip magic byte in JdkZlibDecoder (netty#1…
14da07b
…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`.
@mkurz mkurz mentioned this pull request Nov 5, 2026
Upgrade Netty to 4.2.20.Final AsyncHttpClient/async-http-client#2375
Merged
5 tasks done
hyperxpro pushed a commit to AsyncHttpClient/async-http-client that referenced this pull request Nov 6, 2026
@mkurz @claude
Upgrade Netty to 4.2.20.Final (#2375)
70e775e
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.20.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Marti2203 @netty-project-bot @normanmaurer
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.