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 — Auto-port 4.1: Only fail in ZlibDecoder when the decompression buffer is full by netty-project-bot · Pull Request #17698 · netty/netty

Conversation

@netty-project-bot

@netty-project-bot netty-project-bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Auto-port of #17692 to 4.1
Cherry-picked commit: e6fc471


Motivation:

Since #17370 (and #17392 for JZlibDecoder), the zlib decoders ask ZlibDecoder.prepareDecompressBuffer(...) for at least 512 bytes (MIN_OUTPUT_BUFFER_SIZE) whenever an inflate call did not finish the stream. prepareDecompressBuffer throws as soon as ensureWritable(preferredSize, true) returns 1, that is, when the buffer is already at maxAllocation and has fewer writable bytes than requested. It does not check whether the buffer still has room.

So with a maxAllocation of 512 or less, the decoder throws DecompressionException: Decompression buffer has reached maximum size for every stream that arrives in more than one read, even when the buffer is empty. For example, a ZLIB stream of 36 bytes of output with maxAllocation = 375, split into two reads, is rejected. With a larger maxAllocation the same happens once the buffer holds more than maxAllocation - 512 bytes and the stream continues, although the remaining space would be used by the next inflate call.

Measured with 2,000 random streams per row and wrapper (ZLIB, GZIP, NONE), split into two reads, whose whole output fits into maxAllocation:

maxAllocation JdkZlibDecoder 4.2.18 before #17370 with this change
1-512 73-100% fail 0 0 (1)
513-1100 about 8% fail 0 0
4096-70000 2 of 6,000 fail 0 0

(1) except when one read produces exactly maxAllocation bytes and the stream continues; see below.

JZlibDecoder also requests max(2 * remaining input, 512) bytes before its first inflate. When 2 * input > maxAllocation, an input whose output fits is rejected before any byte is decompressed: a single read that holds a ZLIB stream of 600 random bytes fails with maxAllocation = 1024. That part predates #17392.

#17364 was merged into 4.1 as well, so 4.1.138.Final has the same behaviour for JdkZlibDecoder.

The javadoc of prepareDecompressBuffer already says that it calls decompressionBufferExhausted(...) "if the buffer is full and cannot be expanded further".

Modification:

  • In ZlibDecoder.prepareDecompressBuffer(...), only give up when the buffer could not be expanded and has no writable byte left. Until then the decoder keeps inflating into the space that is left, and a stream whose output exceeds maxAllocation still fails as before.
  • New tests in ZlibTest, so they run for both JdkZlibDecoder and JZlibDecoder:
    • @ParameterizedTest over ZLIB, GZIP and NONE with maxAllocation 2, 64 and 512: an output smaller than maxAllocation, decoded in one read, in two reads and byte by byte;
    • @ParameterizedTest over 600, 1000 and 1024 incompressible bytes with maxAllocation = 1024 in one read.
    • a guard, @ParameterizedTest over ZLIB, GZIP and NONE with maxAllocation 64, and ZLIB with 512: 64 KiB of zeros (about 100 bytes compressed) in one read is still rejected with "Decompression buffer has reached maximum size", so the limit keeps protecting against small inputs with a large output.

Result:

maxAllocation limits the output of a read again, without rejecting streams whose output fits.

  • JdkZlibTest (44) and JZlibTest (26) pass. Without the change to ZlibDecoder, 7 of the new tests fail for JdkZlibDecoder and 10 for JZlibDecoder; the incompressible cases pass for JdkZlibDecoder both ways, and the guard and the existing testMaxAllocation (a 1 MiB output in one read must fail) pass both ways.
  • codec-compression tests: 548 tests, 0 failures. Checkstyle and revapi pass.
  • The table above was produced by the same random check with the change.

Not changed: a read whose output is exactly maxAllocation bytes, while the stream continues, still fails as on 4.2.18. The decoder cannot tell whether more output is pending without a larger buffer.

The problem was found by a randomized split-input check of all decoders, and the buffer logic was modelled in Lean 4 (the changed method throws only when the buffer is full, and never where it did not throw before). The change was prepared with Claude Code (Claude Opus 5.5), and the commit has a Co-Authored-By trailer.

Prepared with Claude Code on behalf of allthingssecurity.

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

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

All reactions
@allthingssecurity @netty-project-bot
Only fail in ZlibDecoder when the decompression buffer is full (#17692)
8ad2b8e
Motivation:

Since #17370 (and #17392 for `JZlibDecoder`), the zlib decoders ask
`ZlibDecoder.prepareDecompressBuffer(...)` for at least 512 bytes
(`MIN_OUTPUT_BUFFER_SIZE`) whenever an `inflate` call did not finish the
stream. `prepareDecompressBuffer` throws as soon as
`ensureWritable(preferredSize, true)` returns 1, that is, when the
buffer is already at `maxAllocation` and has fewer writable bytes than
requested. It does not check whether the buffer still has room.

So with a `maxAllocation` of 512 or less, the decoder throws
`DecompressionException: Decompression buffer has reached maximum size`
for every stream that arrives in more than one read, even when the
buffer is empty. For example, a ZLIB stream of 36 bytes of output with
`maxAllocation = 375`, split into two reads, is rejected. With a larger
`maxAllocation` the same happens once the buffer holds more than
`maxAllocation - 512` bytes and the stream continues, although the
remaining space would be used by the next `inflate` call.

Measured with 2,000 random streams per row and wrapper (ZLIB, GZIP,
NONE), split into two reads, whose whole output fits into
`maxAllocation`:

| `maxAllocation` | `JdkZlibDecoder` 4.2.18 | before #17370 | with this
change |
|---|---|---|---|
| 1-512 | 73-100% fail | 0 | 0 (1) |
| 513-1100 | about 8% fail | 0 | 0 |
| 4096-70000 | 2 of 6,000 fail | 0 | 0 |

(1) except when one read produces exactly `maxAllocation` bytes and the
stream continues; see below.

`JZlibDecoder` also requests `max(2 * remaining input, 512)` bytes
before its first `inflate`. When `2 * input > maxAllocation`, an input
whose output fits is rejected before any byte is decompressed: a single
read that holds a ZLIB stream of 600 random bytes fails with
`maxAllocation = 1024`. That part predates #17392.

#17364 was merged into 4.1 as well, so 4.1.138.Final has the same
behaviour for `JdkZlibDecoder`.

The javadoc of `prepareDecompressBuffer` already says that it calls
`decompressionBufferExhausted(...)` "if the buffer is full and cannot be
expanded further".

Modification:

- In `ZlibDecoder.prepareDecompressBuffer(...)`, only give up when the
buffer could not be expanded and has no writable byte left. Until then
the decoder keeps inflating into the space that is left, and a stream
whose output exceeds `maxAllocation` still fails as before.
- New tests in `ZlibTest`, so they run for both `JdkZlibDecoder` and
`JZlibDecoder`:
- `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 2,
64 and 512: an output smaller than `maxAllocation`, decoded in one read,
in two reads and byte by byte;
- `@ParameterizedTest` over 600, 1000 and 1024 incompressible bytes with
`maxAllocation = 1024` in one read.
- a guard, `@ParameterizedTest` over ZLIB, GZIP and NONE with
`maxAllocation` 64, and ZLIB with 512: 64 KiB of zeros (about 100 bytes
compressed) in one read is still rejected with "Decompression buffer has
reached maximum size", so the limit keeps protecting against small
inputs with a large output.

Result:

`maxAllocation` limits the output of a read again, without rejecting
streams whose output fits.

(cherry picked from commit e6fc471)
@netty-project-bot netty-project-bot mentioned this pull request Oct 1, 2026
Only fail in ZlibDecoder when the decompression buffer is full #17692
Merged
@normanmaurer
Fix compile error
75e2911
@testlens-app

testlens-app Bot commented Oct 1, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

🚨 All tests passed but jobs failed 🚨

Failed Jobs without Test Failures

❌ Build PR / linux-x86_64-java11-boringssl build

🏷️ Commit: 75e2911
▶️ Tests: 287560 executed
⚪️ Checks: 18/18 completed

Rerun Controls

Click the checkbox to trigger a rerun:

  • Rerun jobs

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 this to the 4.1.139.Final milestone Oct 1, 2026
@normanmaurer
normanmaurer merged commit 8ca236e into 4.1 Oct 1, 2026
18 of 19 checks passed

Uh oh!

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

@normanmaurer
normanmaurer deleted the auto-port-pr-17692-to-4.1 branch October 1, 2026 13:52
normanmaurer added a commit that referenced this pull request Oct 1, 2026
@normanmaurer @netty-project-bot @allthingssecurity
Port: Only fail in ZlibDecoder when the decompression buffer is full (#…
8b401cb
…17698) (#17704)

Motivation:

Since #17370 (and #17392 for `JZlibDecoder`), the zlib decoders ask
`ZlibDecoder.prepareDecompressBuffer(...)` for at least 512 bytes
(`MIN_OUTPUT_BUFFER_SIZE`) whenever an `inflate` call did not finish the
stream. `prepareDecompressBuffer` throws as soon as
`ensureWritable(preferredSize, true)` returns 1, that is, when the
buffer is already at `maxAllocation` and has fewer writable bytes than
requested. It does not check whether the buffer still has room.

So with a `maxAllocation` of 512 or less, the decoder throws
`DecompressionException: Decompression buffer has reached maximum size`
for every stream that arrives in more than one read, even when the
buffer is empty. For example, a ZLIB stream of 36 bytes of output with
`maxAllocation = 375`, split into two reads, is rejected. With a larger
`maxAllocation` the same happens once the buffer holds more than
`maxAllocation - 512` bytes and the stream continues, although the
remaining space would be used by the next `inflate` call.

Measured with 2,000 random streams per row and wrapper (ZLIB, GZIP,
NONE), split into two reads, whose whole output fits into
`maxAllocation`:

| `maxAllocation` | `JdkZlibDecoder` 4.2.18 | before #17370 | with this
change |
|---|---|---|---|
| 1-512 | 73-100% fail | 0 | 0 (1) |
| 513-1100 | about 8% fail | 0 | 0 |
| 4096-70000 | 2 of 6,000 fail | 0 | 0 |

(1) except when one read produces exactly `maxAllocation` bytes and the
stream continues; see below.

`JZlibDecoder` also requests `max(2 * remaining input, 512)` bytes
before its first `inflate`. When `2 * input > maxAllocation`, an input
whose output fits is rejected before any byte is decompressed: a single
read that holds a ZLIB stream of 600 random bytes fails with
`maxAllocation = 1024`. That part predates #17392.

behaviour for `JdkZlibDecoder`.

The javadoc of `prepareDecompressBuffer` already says that it calls
`decompressionBufferExhausted(...)` "if the buffer is full and cannot be
expanded further".

Modification:

- In `ZlibDecoder.prepareDecompressBuffer(...)`, only give up when the
buffer could not be expanded and has no writable byte left. Until then
the decoder keeps inflating into the space that is left, and a stream
whose output exceeds `maxAllocation` still fails as before.
- New tests in `ZlibTest`, so they run for both `JdkZlibDecoder` and
`JZlibDecoder`:
- `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 2,
64 and 512: an output smaller than `maxAllocation`, decoded in one read,
in two reads and byte by byte;
- `@ParameterizedTest` over 600, 1000 and 1024 incompressible bytes with
`maxAllocation = 1024` in one read.
- a guard, `@ParameterizedTest` over ZLIB, GZIP and NONE with
`maxAllocation` 64, and ZLIB with 512: 64 KiB of zeros (about 100 bytes
compressed) in one read is still rejected with "Decompression buffer has
reached maximum size", so the limit keeps protecting against small
inputs with a large output.

Result:

`maxAllocation` limits the output of a read again, without rejecting
streams whose output fits.

---------

Co-authored-by: allthingssecurity
<[email protected]>
Co-authored-by: Norman Maurer <[email protected]>

Co-authored-by: Netty Project Bot <[email protected]>
Co-authored-by: allthingssecurity <[email protected]>
@boloagegit boloagegit mentioned this pull request Oct 21, 2026
【研究總追蹤/選擇性實作】Echo HTTP 大本文、G1 GC、JMS 交易與紀錄穩定性(固定 e94b53a) boloagegit/echo-mock-server#99
Closed
12 tasks
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @allthingssecurity
@normanmaurer @lltopk
Auto-port 4.1: Only fail in ZlibDecoder when the decompression buffer…
04f172b
… is full (netty#17698)

Auto-port of netty#17692 to 4.1
Cherry-picked commit: e6fc471

---
Motivation:

Since netty#17370 (and netty#17392 for `JZlibDecoder`), the zlib decoders ask
`ZlibDecoder.prepareDecompressBuffer(...)` for at least 512 bytes
(`MIN_OUTPUT_BUFFER_SIZE`) whenever an `inflate` call did not finish the
stream. `prepareDecompressBuffer` throws as soon as
`ensureWritable(preferredSize, true)` returns 1, that is, when the
buffer is already at `maxAllocation` and has fewer writable bytes than
requested. It does not check whether the buffer still has room.

So with a `maxAllocation` of 512 or less, the decoder throws
`DecompressionException: Decompression buffer has reached maximum size`
for every stream that arrives in more than one read, even when the
buffer is empty. For example, a ZLIB stream of 36 bytes of output with
`maxAllocation = 375`, split into two reads, is rejected. With a larger
`maxAllocation` the same happens once the buffer holds more than
`maxAllocation - 512` bytes and the stream continues, although the
remaining space would be used by the next `inflate` call.

Measured with 2,000 random streams per row and wrapper (ZLIB, GZIP,
NONE), split into two reads, whose whole output fits into
`maxAllocation`:

| `maxAllocation` | `JdkZlibDecoder` 4.2.18 | before netty#17370 | with this
change |
|---|---|---|---|
| 1-512 | 73-100% fail | 0 | 0 (1) |
| 513-1100 | about 8% fail | 0 | 0 |
| 4096-70000 | 2 of 6,000 fail | 0 | 0 |

(1) except when one read produces exactly `maxAllocation` bytes and the
stream continues; see below.

`JZlibDecoder` also requests `max(2 * remaining input, 512)` bytes
before its first `inflate`. When `2 * input > maxAllocation`, an input
whose output fits is rejected before any byte is decompressed: a single
read that holds a ZLIB stream of 600 random bytes fails with
`maxAllocation = 1024`. That part predates netty#17392.

netty#17364 was merged into 4.1 as well, so 4.1.138.Final has the same
behaviour for `JdkZlibDecoder`.

The javadoc of `prepareDecompressBuffer` already says that it calls
`decompressionBufferExhausted(...)` "if the buffer is full and cannot be
expanded further".

Modification:

- In `ZlibDecoder.prepareDecompressBuffer(...)`, only give up when the
buffer could not be expanded and has no writable byte left. Until then
the decoder keeps inflating into the space that is left, and a stream
whose output exceeds `maxAllocation` still fails as before.
- New tests in `ZlibTest`, so they run for both `JdkZlibDecoder` and
`JZlibDecoder`:
- `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 2,
64 and 512: an output smaller than `maxAllocation`, decoded in one read,
in two reads and byte by byte;
- `@ParameterizedTest` over 600, 1000 and 1024 incompressible bytes with
`maxAllocation = 1024` in one read.
- a guard, `@ParameterizedTest` over ZLIB, GZIP and NONE with
`maxAllocation` 64, and ZLIB with 512: 64 KiB of zeros (about 100 bytes
compressed) in one read is still rejected with "Decompression buffer has
reached maximum size", so the limit keeps protecting against small
inputs with a large output.

Result:

`maxAllocation` limits the output of a read again, without rejecting
streams whose output fits.

---------

Co-authored-by: allthingssecurity <[email protected]>
Co-authored-by: Norman Maurer <[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.1.139.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

@netty-project-bot @normanmaurer @allthingssecurity
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.