Skip to content

Auto-port 4.1: Don't count STOMP headers again when the header block is replayed - #17716

Merged
normanmaurer merged 3 commits into
4.1from
auto-port-pr-17664-to-4.1
Oct 2, 2026
Merged

normanmaurer merged 3 commits into
4.1from
auto-port-pr-17664-to-4.1

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #17664 to 4.1
Cherry-picked commit: f364155


Motivation:

StompSubframeDecoder is a ReplayingDecoder. When the header block of a frame is not complete, the next read parses the command and all headers again from the checkpoint. The counter that enforces maxNumHeaders (HeaderParser.numHeaders, added in #17063) is only reset by the empty line that ends the headers. So every replay adds the headers that were already counted.

As a result, whether a valid frame is rejected with "maximum number of headers exceeded" depends on how it is split into reads. After the rejection, the decoder stays in BAD_FRAME. With the default limit of 128:

Frame Reads Result
15 headers sent byte by byte, or one line at a time from a terminal rejected
40 headers 32-byte reads rejected
128 headers 2 reads rejected
90 headers one read accepted

Modification:

  • Reset the counter at the start of readHeaders(). Each attempt parses all headers of the frame again, so it counts from zero.
  • New tests in StompSubframeDecoderTest, each with maxNumHeaders = 10 and read sizes of 1, 7, about half the frame and the whole frame:
    • testMaxNumHeadersNotExceededWhenHeadersSplitAcrossReads: a frame with 10 headers is accepted.
    • testMaxNumHeadersEnforcedWhenHeadersSplitAcrossReads: a frame with 11 headers is rejected.

Result:

maxNumHeaders limits the headers of a frame, however the frame is split into reads. The limit itself is unchanged: each attempt still counts every header of the frame.

  • StompSubframeDecoderTest: 28 tests pass. Without the change to StompSubframeDecoder, testMaxNumHeadersNotExceededWhenHeadersSplitAcrossReads fails: read size 1: failure(io.netty.handler.codec.TooLongFrameException: maximum number of headers exceeded: 10).
  • codec-stomp tests: 67, 0 failures. Checkstyle passes.

The problem was found by modelling the replay behaviour of the decoder in Lean 4 and reproducing it with the real class. 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

…7664)

Motivation:

`StompSubframeDecoder` is a `ReplayingDecoder`. When the header block of
a frame is not complete, the next read parses the command and all
headers again from the checkpoint. The counter that enforces
`maxNumHeaders` (`HeaderParser.numHeaders`, added in #17063) is only
reset by the empty line that ends the headers. So every replay adds the
headers that were already counted.

As a result, whether a valid frame is rejected with "maximum number of
headers exceeded" depends on how it is split into reads. After the
rejection, the decoder stays in `BAD_FRAME`. With the default limit of
128:

| Frame | Reads | Result |
|---|---|---|
| 15 headers | sent byte by byte, or one line at a time from a terminal
| rejected |
| 40 headers | 32-byte reads | rejected |
| 128 headers | 2 reads | rejected |
| 90 headers | one read | accepted |

Modification:

- Reset the counter at the start of `readHeaders()`. Each attempt parses
all headers of the frame again, so it counts from zero.
- New tests in `StompSubframeDecoderTest`, each with `maxNumHeaders =
10` and read sizes of 1, 7, about half the frame and the whole frame:
- `testMaxNumHeadersNotExceededWhenHeadersSplitAcrossReads`: a frame
with 10 headers is accepted.
- `testMaxNumHeadersEnforcedWhenHeadersSplitAcrossReads`: a frame with
11 headers is rejected.

Result:

`maxNumHeaders` limits the headers of a frame, however the frame is
split into reads. The limit itself is unchanged: each attempt still
counts every header of the frame.

- `StompSubframeDecoderTest`: 28 tests pass. Without the change to
`StompSubframeDecoder`,
`testMaxNumHeadersNotExceededWhenHeadersSplitAcrossReads` fails: `read
size 1: failure(io.netty.handler.codec.TooLongFrameException: maximum
number of headers exceeded: 10)`.
- `codec-stomp` tests: 67, 0 failures. Checkstyle passes.

The problem was found by modelling the replay behaviour of the decoder
in Lean 4 and reproducing it with the real class. 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](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
(cherry picked from commit f364155)
@normanmaurer normanmaurer added this to the 4.1.139.Final milestone Oct 2, 2026
@testlens-app

This comment has been minimized.

@normanmaurer
normanmaurer merged commit 67eb4c3 into 4.1 Oct 2, 2026
18 checks passed
@normanmaurer
normanmaurer deleted the auto-port-pr-17664-to-4.1 branch October 2, 2026 09:23
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…is replayed (netty#17716)

Auto-port of netty#17664 to 4.1
Cherry-picked commit: f364155

---
Motivation:

`StompSubframeDecoder` is a `ReplayingDecoder`. When the header block of
a frame is not complete, the next read parses the command and all
headers again from the checkpoint. The counter that enforces
`maxNumHeaders` (`HeaderParser.numHeaders`, added in netty#17063) is only
reset by the empty line that ends the headers. So every replay adds the
headers that were already counted.

As a result, whether a valid frame is rejected with "maximum number of
headers exceeded" depends on how it is split into reads. After the
rejection, the decoder stays in `BAD_FRAME`. With the default limit of
128:

| Frame | Reads | Result |
|---|---|---|
| 15 headers | sent byte by byte, or one line at a time from a terminal
| rejected |
| 40 headers | 32-byte reads | rejected |
| 128 headers | 2 reads | rejected |
| 90 headers | one read | accepted |

Modification:

- Reset the counter at the start of `readHeaders()`. Each attempt parses
all headers of the frame again, so it counts from zero.
- New tests in `StompSubframeDecoderTest`, each with `maxNumHeaders =
10` and read sizes of 1, 7, about half the frame and the whole frame:
- `testMaxNumHeadersNotExceededWhenHeadersSplitAcrossReads`: a frame
with 10 headers is accepted.
- `testMaxNumHeadersEnforcedWhenHeadersSplitAcrossReads`: a frame with
11 headers is rejected.

Result:

`maxNumHeaders` limits the headers of a frame, however the frame is
split into reads. The limit itself is unchanged: each attempt still
counts every header of the frame.


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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants