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 — Fix ZstdDecoder and ZstdDecompressor with a non-positive defaultMaxForwardBytes by mkurz · Pull Request #18289 · netty/netty

Conversation

@mkurz

@mkurz mkurz commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Motivation:

Since #17896, ZstdDecoder sizes its output buffers as the smaller of maxForwardBytes and the frame content size. With a maximumAllocationSize of 0, which HttpContentDecompressor and DelegatingDecompressorFrameListener pass by default, maxForwardBytes is io.netty.compression.defaultMaxForwardBytes. When that property is set to 0, every output buffer has a capacity of 0, so nothing is decompressed and only empty buffers are forwarded: a zstd body comes out empty, without an error. Below 0, the allocation fails with initialCapacity : -1. Before #17896, both decoded the body.

Modification:

  • Size the output buffers from maxForwardBytes only when it is positive, and use 64 KiB, the property's default, otherwise. The forwarding threshold itself is unchanged.
  • Don't forward empty buffers, which a threshold of 0 or less also did before Don't size ZstdDecoder output buffers from the frame content size #17896, once the output was drained.
  • Add a package-private constructor that takes the default threshold, and a test that decodes a 1 MiB body with thresholds of 0 and -1.

Result:

ZstdDecoder decodes zstd bodies again when io.netty.compression.defaultMaxForwardBytes is 0 or negative, and the frame header still cannot drive the allocation size.

Sorry, something went wrong.

Uh oh!

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

All reactions
@mkurz
Fix ZstdDecoder with a non-positive defaultMaxForwardBytes
2b9371c
Motivation:

Since netty#17896, ZstdDecoder sizes its output buffers as the smaller of
maxForwardBytes and the frame content size. With a
maximumAllocationSize of 0, which HttpContentDecompressor and
DelegatingDecompressorFrameListener pass by default,
maxForwardBytes is io.netty.compression.defaultMaxForwardBytes. When
that property is set to 0, every output buffer has a capacity of 0, so
nothing is decompressed and only empty buffers are forwarded: a zstd
body comes out empty, without an error. Below 0, the allocation fails
with "initialCapacity : -1". Before netty#17896, both decoded the body.

Modification:

- Size the output buffers from maxForwardBytes only when it is
  positive, and use 64 KiB, the property's default, otherwise. The
  forwarding threshold itself is unchanged.
- Don't forward empty buffers, which a threshold of 0 or less also did
  before netty#17896, once the output was drained.
- Add a package-private constructor that takes the default threshold,
  and a test that decodes a 1 MiB body with thresholds of 0 and -1.

Result:

ZstdDecoder decodes zstd bodies again when
io.netty.compression.defaultMaxForwardBytes is 0 or negative, and the
frame header still cannot drive the allocation size.
@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]>
@normanmaurer normanmaurer added this to the 4.2.21.Final milestone Nov 12, 2026
LI123456mo

This comment was marked as duplicate.

Sign in to view

Sorry, something went wrong.

Uh oh!

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

@LI123456mo LI123456mo mentioned this pull request Nov 13, 2026
Avoid extra buffer allocation when growing a full CompositeByteBuf #18228
Merged
normanmaurer
normanmaurer requested changes Nov 13, 2026
View reviewed changes

@normanmaurer normanmaurer left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

ZstdDecompressor.takeOutput() looks like it has the same problem for a non-positive io.netty.compression.defaultMaxForwardBytes:

ByteBuf buf = allocator.buffer(DEFAULT_MAX_FORWARD_BYTES, DEFAULT_MAX_FORWARD_BYTES);
buf.writeBytes(output, DEFAULT_MAX_FORWARD_BYTES);
With the property at 0, the buffer has capacity 0 and nothing is written, so takeOutput() returns EMPTY_BUFFER on every call. Below 0, allocator.buffer(-1, -1) throws IllegalArgumentException.

Could we apply the same fallback here, and share the 64 KiB constant with ZstdDecoder.DEFAULT_OUTPUT_BUFFER_SIZE so the two can't drift apart? A test for the Decompressor path would also be good.

Sorry, something went wrong.

Uh oh!

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

All reactions
@mkurz
Fix ZstdDecompressor with a non-positive defaultMaxForwardBytes
5f85d55
Motivation:

ZstdDecompressor.takeOutput() allocates its buffer with
io.netty.compression.defaultMaxForwardBytes as both capacity and
maximum. At 0, nothing is written, so takeOutput() returns an empty
buffer on every call while status() stays NEED_OUTPUT. Below 0, the
allocation fails with "initialCapacity : -1".

Modification:

- Size the output buffer from the property only when it is positive,
  and use ZstdDecoder.DEFAULT_OUTPUT_BUFFER_SIZE (64 KiB) otherwise, so
  that both zstd paths share the fallback.
- Add a package-private constructor that takes the default, and a test
  that decompresses a 1 MiB body with 0 and -1.

Result:

ZstdDecompressor decompresses zstd input when
io.netty.compression.defaultMaxForwardBytes is 0 or negative.
@mkurz mkurz changed the title Fix ZstdDecoder with a non-positive defaultMaxForwardBytes Fix ZstdDecoder and ZstdDecompressor with a non-positive defaultMaxForwardBytes Nov 13, 2026
@mkurz

mkurz commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, done in 5f85d55: ZstdDecompressor now uses the same 64 KiB fallback, shared through ZstdDecoder.DEFAULT_OUTPUT_BUFFER_SIZE, and ZstdDecompressorTest covers 0 and -1.

All reactions

Sorry, something went wrong.

Uh oh!

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

@testlens-app

testlens-app Bot commented Nov 13, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 5f85d55
▶️ Tests: 44445 executed
🟡 Checks: 30/33 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 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 Nov 13, 2026
@normanmaurer
normanmaurer merged commit 5baf6f3 into netty:4.2 Nov 13, 2026
31 checks passed

Uh oh!

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

@netty-project-bot netty-project-bot mentioned this pull request Nov 13, 2026
Auto-port 5.0: Fix ZstdDecoder and ZstdDecompressor with a non-positive defaultMaxForwardBytes #18383
Merged
@netty-project-bot

netty-project-bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #18383

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 Nov 13, 2026
@netty-project-bot

netty-project-bot commented Nov 13, 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.

chrisvest added a commit that referenced this pull request Nov 13, 2026
@netty-project-bot @mkurz @chrisvest
Auto-port 5.0: Fix ZstdDecoder and ZstdDecompressor with a non-positi…
b4b1074
…ve defaultMaxForwardBytes (#18383)

Auto-port of #18289 to 5.0
Cherry-picked commit: 5baf6f3

---
Motivation:

Since #17896, `ZstdDecoder` sizes its output buffers as the smaller of
`maxForwardBytes` and the frame content size. With a
`maximumAllocationSize` of 0, which `HttpContentDecompressor` and
`DelegatingDecompressorFrameListener` pass by default, `maxForwardBytes`
is `io.netty.compression.defaultMaxForwardBytes`. When that property is
set to 0, every output buffer has a capacity of 0, so nothing is
decompressed and only empty buffers are forwarded: a zstd body comes out
empty, without an error. Below 0, the allocation fails with
`initialCapacity : -1`. Before #17896, both decoded the body.

Modification:

- Size the output buffers from `maxForwardBytes` only when it is
positive, and use 64 KiB, the property's default, otherwise. The
forwarding threshold itself is unchanged.
- Don't forward empty buffers, which a threshold of 0 or less also did
before #17896, once the output was drained.
- Add a package-private constructor that takes the default threshold,
and a test that decodes a 1 MiB body with thresholds of 0 and -1.

Result:

`ZstdDecoder` decodes zstd bodies again when
`io.netty.compression.defaultMaxForwardBytes` is 0 or negative, and the
frame header still cannot drive the allocation size.

---------

Co-authored-by: Matthias Kurz <[email protected]>
Co-authored-by: Chris Vest <[email protected]>
@chrisvest

chrisvest commented Nov 13, 2026

Copy link
Copy Markdown
Member

4.1 port #18401

All reactions

Sorry, something went wrong.

Uh oh!

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

@chrisvest chrisvest removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Nov 13, 2026
chrisvest added a commit that referenced this pull request Nov 13, 2026
@chrisvest
Port 4.1: Fix ZstdDecoder with a non-positive defaultMaxForwardBytes (#…
2823e58
…18289) (#18401)

Motivation:

Since #17896, `ZstdDecoder` sizes its output buffers as the smaller of
`maxForwardBytes` and the frame content size. With a
`maximumAllocationSize` of 0, which `HttpContentDecompressor` and
`DelegatingDecompressorFrameListener` pass by default, `maxForwardBytes`
is `io.netty.compression.defaultMaxForwardBytes`. When that property is
set to 0, every output buffer has a capacity of 0, so nothing is
decompressed and only empty buffers are forwarded: a zstd body comes out
empty, without an error. Below 0, the allocation fails with
`initialCapacity : -1`. Before #17896, both decoded the body.

Modification:

- Size the output buffers from `maxForwardBytes` only when it is
positive, and use 64 KiB, the property's default, otherwise. The
forwarding threshold itself is unchanged.
- Don't forward empty buffers, which a threshold of 0 or less also did
before #17896, once the output was drained.
- Add a package-private constructor that takes the default threshold,
and a test that decodes a 1 MiB body with thresholds of 0 and -1.

Result:

`ZstdDecoder` decodes zstd bodies again when
`io.netty.compression.defaultMaxForwardBytes` is 0 or negative, and the
frame header still cannot drive the allocation size.

(cherry picked from commit 5baf6f3)

4.1 port: `ZstdDecompressor` does not exist on 4.1, so only the
`ZstdDecoder` part is ported; files live in `codec/` instead of
`codec-compression/`.
@mkurz
mkurz deleted the fix/zstd-decoder-non-positive-forward-bytes branch November 14, 2026 18:18
@mkurz mkurz mentioned this pull request Nov 18, 2026
Upgrade Netty to 4.2.21.Final AsyncHttpClient/async-http-client#2395
Merged
6 tasks done
hyperxpro pushed a commit to AsyncHttpClient/async-http-client that referenced this pull request Nov 21, 2026
@mkurz @claude
Upgrade Netty to 4.2.21.Final (#2395)
8f6d126
## Summary

- Upgrades Netty from 4.2.20.Final to
[4.2.21.Final](https://github.com/netty/netty/releases/tag/netty-4.2.21.Final).
It mainly reverts a build mistake in 4.2.20: Netty's native libraries
for x86_64 and aarch64 required glibc 2.33. AHC declares the native
epoll and io_uring jars at its Netty version, and when they do not load,
it falls back to NIO, silently unless `useNativeTransport` is set. On
4.2.20 that would happen on systems with an older glibc, such as RHEL 8
or Ubuntu 20.04. AHC 3.0.14 used Netty 4.2.18, so no AHC release has
4.2.20.
- 4.2.21 also fixes `ZstdDecoder` and `ZstdDecompressor` at a
non-positive `io.netty.compression.defaultMaxForwardBytes`
(netty/netty#18289). This PR drops AHC's workarounds for that bug, so
zstd now waits for demand at any value of the property, like br and
snappy. A zero or negative value of the property now needs Netty 4.2.21
or later.

## Change

- **Netty 4.2.21.Final.**
- **Drop the `ZstdDecoder` replacement from #2375.** At a non-positive
value of the property, `Http1ContentDecompressor` replaced the
`ZstdDecoder` that `HttpContentDecompressor` creates with one whose
buffers hold `MAX_PART_SIZE`, because Netty's decoder handed on an empty
body at 0 and failed below it.
- **Drop the zstd guard from #2362.** At such a value, zstd went to
`HttpContentDecompressor` instead of `PullDecompression`, because
Netty's `ZstdDecompressor` handed out nothing at 0 while reporting more
output. It now takes the pull path there too:
  - it waits for demand;
  - parts are at most 64 KiB;
  - the size limit applies;
- a truncated stream fails with `Truncated zstd stream` instead of
ending quietly.
- **Docs:** the README and the Javadoc of
`ResponseBodyControl.suspend()` and of `Http1ContentDecompressor` no
longer make an exception for zstd. The README and `suspend()` say
instead that a zero or negative value of the property needs Netty 4.2.21
or later. With Netty 4.2.17 to 4.2.20, zstd responses then fail at a
negative value, and at 0 they never end and keep the event loop busy, as
Netty's `ZstdDecompressor` hands out empty buffers while it reports more
output. `MAX_FORWARD_BYTES` is private, since only
`Http1ContentDecompressor` uses it now.
- **Test:** `Http1ContentDecompressorForwardThresholdTest` runs with the
property at 0 and -1 in a fresh JVM. It now also checks zstd while
suspending after every part (one part per resume, none larger than
`MAX_PART_SIZE`) and a truncated zstd body (it fails, and nothing is
left allocated).

## Notes

- With the property at its default (64 KiB), nothing changes for zstd.
- Other changes in 4.2.21 that touch AHC's paths:
- Netty now also rejects control characters such as NUL and ESC, and
DEL, in a response's reason phrase (netty/netty#18331). CR and LF were
already rejected; HTAB is still allowed.
  - `SslHandler` changes: netty/netty#18253, #18323, #18363 and #18406.
  
  AHC's tests pass without changes.

## AI disclosure

Claude Code on behalf of Matthias Kurz. The commit includes
`Co-Authored-By` per `AGENTS.md`.

## Test plan

- [x] `./mvnw -B -ntp -Dgpg.skip=true clean verify` on JDK 11: 2,098
tests, 0 failures, 0 errors, 11 skipped; Revapi passed. No test-skipping
flags were used.
- [x] With the README and Javadoc change from review (`5fd35bad8`), the
same `clean verify`: 2,098 tests, 0 failures, 0 errors, 22 skipped;
Revapi passed. Docker was not running, so the 11 Testcontainers proxy
tests skipped themselves; they ran and passed in the runs above, on the
same code.
- [x] The version change alone, without the other changes, passes the
same `clean verify`: 2,098 tests, 0 failures.
- [x] The extended test fails where it should:
- with the guard put back, at 0 and -1: "the suspended zstd body did not
wait for demand after its first part";
- without the workarounds on Netty 4.2.20: at 0, the check hangs until
its 60 s timeout; at -1, it fails with `IllegalArgumentException:
initialCapacity : -1`.
- [x] The `Http1ContentDecompressor*Test`,
`Http2ContentDecompressorTest`, `Http1Decompression*Test` and
`ResponseBodyControlTest` classes: 142 tests, 0 failures.
- [x] Merged with #2394 (`ef18b0b68`): no conflicts; the same classes,
203 tests, 0 failures; `clean verify` on JDK 11, 2,159 tests, 0
failures, 0 errors, 11 skipped; Revapi passed.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@mkurz mkurz mentioned this pull request Nov 26, 2026
Decide streamed-body resumes through ResponseBodyControl.execute and document AHC 3.0.15 playframework/play-ws#1487
Merged
30 of 31 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer requested changes
+1 more reviewer
@LI123456mo LI123456mo LI123456mo left review comments
Reviewers whose approvals may not affect merge requirements

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.21.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

5 participants

@mkurz @netty-project-bot @chrisvest @normanmaurer @LI123456mo
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.