Skip to content

Auto-port 5.0: Reset UTF-8 decode state on CR in StompSubframeDecoder - #17002

Merged
normanmaurer merged 2 commits into
5.0from
auto-port-pr-16991-to-5.0
Jun 26, 2026
Merged

normanmaurer merged 2 commits into
5.0from
auto-port-pr-16991-to-5.0

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #16991 to 5.0
Cherry-picked commit: fc86cc6


Motivation:

When a CR (0x0D) byte appears in the middle of a multi-byte UTF-8 sequence within a STOMP header line, Utf8LineParser.process takes the CR branch and returns early without clearing its partial UTF-8 decode state (interim / nextRead). The next byte is then combined with the stale state and decoded incorrectly, corrupting the decoded value.

For example, a header value made of the bytes 0xC3 0x0D 0x41 (0xC3 starts a 2-byte sequence, CR, then A) decodes to Á instead of A.

Modifications:

Clear interim and nextRead in the CR branch of Utf8LineParser.process, so that a CR resets the UTF-8 decode state. CR is an ASCII control byte and is never a valid UTF-8 lead or continuation byte, so if it interrupts a multi-byte sequence that sequence is malformed and the partial state should be discarded.

Result:

Bytes following a CR are decoded correctly. Adds a regression test (StompSubframeDecoderTest#testCRResetsUtf8DecodeState) that fails before this change (expected: <A> but was: <Á>) and passes after it. The full StompSubframeDecoderTest suite continues to pass.

Motivation:

When a CR (`0x0D`) byte appears in the middle of a multi-byte UTF-8
sequence within a STOMP header line, `Utf8LineParser.process` takes the
CR branch and returns early **without clearing its partial UTF-8 decode
state** (`interim` / `nextRead`). The next byte is then combined with
the stale state and decoded incorrectly, corrupting the decoded value.

For example, a header value made of the bytes `0xC3 0x0D 0x41` (`0xC3`
starts a 2-byte sequence, `CR`, then `A`) decodes to `Á` instead of `A`.

Modifications:

Clear `interim` and `nextRead` in the CR branch of
`Utf8LineParser.process`, so that a CR resets the UTF-8 decode state. CR
is an ASCII control byte and is never a valid UTF-8 lead or continuation
byte, so if it interrupts a multi-byte sequence that sequence is
malformed and the partial state should be discarded.

Result:

Bytes following a CR are decoded correctly. Adds a regression test
(`StompSubframeDecoderTest#testCRResetsUtf8DecodeState`) that fails
before this change (`expected: <A> but was: <Á>`) and passes after it.
The full `StompSubframeDecoderTest` suite continues to pass.

(cherry picked from commit fc86cc6)
@normanmaurer
normanmaurer merged commit d5bdf36 into 5.0 Jun 26, 2026
11 of 13 checks passed
@normanmaurer
normanmaurer deleted the auto-port-pr-16991-to-5.0 branch June 26, 2026 16:02
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