Skip to content

Port 4.1: Fix ZstdDecoder with a non-positive defaultMaxForwardBytes (#18289) - #18401

Merged
chrisvest merged 1 commit into
netty:4.1from
chrisvest:4.1-port-pr-18289
Nov 13, 2026
Merged

chrisvest merged 1 commit into
netty:4.1from
chrisvest:4.1-port-pr-18289

Conversation

@chrisvest

Copy link
Copy Markdown
Member

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.

(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/.

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.

(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/.]
@testlens-app

testlens-app Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: b634675
▶️ Tests: 49302 executed
🟡 Checks: 20/21 completed


Learn more about TestLens at testlens.app/docs.

@chrisvest
chrisvest merged commit 2823e58 into netty:4.1 Nov 13, 2026
19 checks passed
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