Skip to content

ProtobufVarint32FrameDecoder must wait for more data when the length prefix is incomplete - #17550

Merged
normanmaurer merged 1 commit into
netty:4.2from
ohchanKyu:protobuf-varint32-split-prefix
Sep 20, 2026
Merged

normanmaurer merged 1 commit into
netty:4.2from
ohchanKyu:protobuf-varint32-split-prefix

Conversation

@ohchanKyu

Copy link
Copy Markdown
Contributor

Motivation:

Since #14050 two incomplete length prefix cases are no longer treated as "need more data" by ProtobufVarint32FrameDecoder:

  • If only 3 bytes are readable and all of them have the continuation bit set, readRawVarint24 returned the partial value and left the readerIndex advanced. decode() then used the low 21 bits of the real length. When these bits are 0, i.e. the message length is an exact multiple of 2 MiB, an empty frame was emitted, the prefix bytes were consumed and the rest of the stream was decoded from the wrong position. A single 2 MiB message split after the third prefix byte was delivered as about 2 million bogus frames without any exception.
  • If exactly 4 bytes are readable and all of them have the continuation bit set, readRawVarint40 threw a CorruptedFrameException although the fifth byte may simply not have been received yet.

Before #14050 both cases reset the readerIndex and returned 0.

Modifications:

  • readRawVarint24 resets the readerIndex and returns 0 when the third byte still has the continuation bit set.
  • readRawVarint40 returns 0 without moving the readerIndex when only 4 bytes are readable, and only throws when the fifth byte is malformed.
  • Add tests that split 1 to 5 byte length prefixes at every position, including lengths that are exact multiples of 2 MiB.

Result:

ProtobufVarint32FrameDecoder produces the same frames
regardless of how the length prefix is fragmented across reads.

Fixes #17549.

…prefix is incomplete

Motivation:

Since netty#14050 two incomplete length prefix cases are no longer treated as
"need more data" by `ProtobufVarint32FrameDecoder`:

- If only 3 bytes are readable and all of them have the continuation bit
  set, `readRawVarint24` returned the partial value and left the
  readerIndex advanced. `decode()` then used the low 21 bits of the real
  length. When these bits are 0, i.e. the message length is an exact
  multiple of 2 MiB, an empty frame was emitted, the prefix bytes were
  consumed and the rest of the stream was decoded from the wrong
  position. A single 2 MiB message split after the third prefix byte was
  delivered as about 2 million bogus frames without any exception.
- If exactly 4 bytes are readable and all of them have the continuation
  bit set, `readRawVarint40` threw a `CorruptedFrameException` although
  the fifth byte may simply not have been received yet.

Before netty#14050 both cases reset the readerIndex and returned 0.

Modifications:

- `readRawVarint24` resets the readerIndex and returns 0 when the third
  byte still has the continuation bit set.
- `readRawVarint40` returns 0 without moving the readerIndex when only 4
  bytes are readable, and only throws when the fifth byte is malformed.
- Add tests that split 1 to 5 byte length prefixes at every position,
  including lengths that are exact multiples of 2 MiB.

Result:

`ProtobufVarint32FrameDecoder` produces the same frames regardless of how
the length prefix is fragmented across reads.

Fixes netty#17549.
@testlens-app

testlens-app Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

🚨 TestLens detected 2 failed tests 🚨

Here is what you can do:

  1. Inspect the test failures carefully.
  2. If you are convinced that some of the tests are flaky, you can mute them below.
  3. Finally, trigger a rerun by checking the rerun checkbox.

Test Summary

Build PR / macos-aarch64-java11-boringssl build > Netty/Transport/Native/KQueue

Test Runs Flakiness
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeHeapByteBuf(TestInfo) ❌ 2% 🟡
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo) ❌ 5% 🟠

🏷️ Commit: cc73fce
▶️ Tests: 465221 executed
🟡 Checks: 28/29 completed

Test Failures

KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeHeapByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java11-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend0(DatagramUnicastTest.java:368)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend(DatagramUnicastTest.java:194)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeHeapByteBuf(DatagramUnicastTest.java:150)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$4.run(DatagramUnicastTest.java:136)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$4.run(DatagramUnicastTest.java:133)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeHeapByteBuf(DatagramUnicastTest.java:133)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo) (Netty/Transport/Native/KQueue in Build PR / macos-aarch64-java11-boringssl build)
org.opentest4j.AssertionFailedError
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend0(DatagramUnicastTest.java:368)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSend(DatagramUnicastTest.java:194)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeMixedByteBuf(DatagramUnicastTest.java:167)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$5.run(DatagramUnicastTest.java:158)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest$5.run(DatagramUnicastTest.java:155)
	at io.netty.testsuite.transport.AbstractComboTestsuiteTest.run(AbstractComboTestsuiteTest.java:52)
	at io.netty.testsuite.transport.socket.DatagramUnicastTest.testSimpleSendCompositeMixedByteBuf(DatagramUnicastTest.java:155)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

Rerun Controls

Note

Checks are currently running using the configuration below.

Select tests to mute in this pull request:

🔲 KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeHeapByteBuf(TestInfo)
🔲 KQueueDatagramUnicastIPv6MappedTest > testSimpleSendCompositeMixedByteBuf(TestInfo)

Reuse successful test results:

🔲 ♻️ Only rerun the tests that failed or were muted before

Click the checkbox to trigger a rerun:

🔲 Rerun jobs


Learn more about TestLens at testlens.app/docs.

@franz1981 franz1981 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@normanmaurer normanmaurer added this to the 4.2.19.Final milestone Sep 20, 2026
@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 Sep 20, 2026
@normanmaurer
normanmaurer merged commit 335aed7 into netty:4.2 Sep 20, 2026
28 of 30 checks passed
@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.1: #17553

@github-actions github-actions Bot removed the needs-cherry-pick-4.1 This PR should be cherry-picked to 4.1 once merged. label Sep 20, 2026
@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port PR for 5.0: #17554

@github-actions github-actions Bot removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Sep 20, 2026
normanmaurer added a commit that referenced this pull request Sep 20, 2026
…hen the length prefix is incomplete (#17553)

Auto-port of #17550 to 4.1
Cherry-picked commit: 335aed7

---
Motivation:

Since #14050 two incomplete length prefix cases are no longer treated as
"need more data" by `ProtobufVarint32FrameDecoder`:

- If only 3 bytes are readable and all of them have the continuation bit
set, `readRawVarint24` returned the partial value and left the
readerIndex advanced. `decode()` then used the low 21 bits of the real
length. When these bits are 0, i.e. the message length is an exact
multiple of 2 MiB, an empty frame was emitted, the prefix bytes were
consumed and the rest of the stream was decoded from the wrong position.
A single 2 MiB message split after the third prefix byte was delivered
as about 2 million bogus frames without any exception.
- If exactly 4 bytes are readable and all of them have the continuation
bit set, `readRawVarint40` threw a `CorruptedFrameException` although
the fifth byte may simply not have been received yet.

Before #14050 both cases reset the readerIndex and returned 0.

Modifications:

- `readRawVarint24` resets the readerIndex and returns 0 when the third
byte still has the continuation bit set.
- `readRawVarint40` returns 0 without moving the readerIndex when only 4
bytes are readable, and only throws when the fifth byte is malformed.
- Add tests that split 1 to 5 byte length prefixes at every position,
including lengths that are exact multiples of 2 MiB.

Result:

`ProtobufVarint32FrameDecoder` produces the same frames 
regardless of how the length prefix is fragmented across reads.

Fixes #17549.

---------

Co-authored-by: 오규찬 (B팀 서버) <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 20, 2026
…hen the length prefix is incomplete (#17554)

Auto-port of #17550 to 5.0
Cherry-picked commit: 335aed7

---
Motivation:

Since #14050 two incomplete length prefix cases are no longer treated as
"need more data" by `ProtobufVarint32FrameDecoder`:

- If only 3 bytes are readable and all of them have the continuation bit
set, `readRawVarint24` returned the partial value and left the
readerIndex advanced. `decode()` then used the low 21 bits of the real
length. When these bits are 0, i.e. the message length is an exact
multiple of 2 MiB, an empty frame was emitted, the prefix bytes were
consumed and the rest of the stream was decoded from the wrong position.
A single 2 MiB message split after the third prefix byte was delivered
as about 2 million bogus frames without any exception.
- If exactly 4 bytes are readable and all of them have the continuation
bit set, `readRawVarint40` threw a `CorruptedFrameException` although
the fifth byte may simply not have been received yet.

Before #14050 both cases reset the readerIndex and returned 0.

Modifications:

- `readRawVarint24` resets the readerIndex and returns 0 when the third
byte still has the continuation bit set.
- `readRawVarint40` returns 0 without moving the readerIndex when only 4
bytes are readable, and only throws when the fifth byte is malformed.
- Add tests that split 1 to 5 byte length prefixes at every position,
including lengths that are exact multiples of 2 MiB.

Result:

`ProtobufVarint32FrameDecoder` produces the same frames 
regardless of how the length prefix is fragmented across reads.

Fixes #17549.

---------

Co-authored-by: 오규찬 (B팀 서버) <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…hen the length prefix is incomplete (netty#17553)

Auto-port of netty#17550 to 4.1
Cherry-picked commit: 335aed7

---
Motivation:

Since netty#14050 two incomplete length prefix cases are no longer treated as
"need more data" by `ProtobufVarint32FrameDecoder`:

- If only 3 bytes are readable and all of them have the continuation bit
set, `readRawVarint24` returned the partial value and left the
readerIndex advanced. `decode()` then used the low 21 bits of the real
length. When these bits are 0, i.e. the message length is an exact
multiple of 2 MiB, an empty frame was emitted, the prefix bytes were
consumed and the rest of the stream was decoded from the wrong position.
A single 2 MiB message split after the third prefix byte was delivered
as about 2 million bogus frames without any exception.
- If exactly 4 bytes are readable and all of them have the continuation
bit set, `readRawVarint40` threw a `CorruptedFrameException` although
the fifth byte may simply not have been received yet.

Before netty#14050 both cases reset the readerIndex and returned 0.

Modifications:

- `readRawVarint24` resets the readerIndex and returns 0 when the third
byte still has the continuation bit set.
- `readRawVarint40` returns 0 without moving the readerIndex when only 4
bytes are readable, and only throws when the fifth byte is malformed.
- Add tests that split 1 to 5 byte length prefixes at every position,
including lengths that are exact multiples of 2 MiB.

Result:

`ProtobufVarint32FrameDecoder` produces the same frames 
regardless of how the length prefix is fragmented across reads.

Fixes netty#17549.

---------

Co-authored-by: 오규찬 (B팀 서버) <[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.

ProtobufVarint32FrameDecoder desynchronizes the stream when a 4-byte length prefix is split after 3 bytes

4 participants