Repository navigation
Auto-port 5.0: Reset LengthFieldBasedFrameDecoder state when the frame is shorter than initialBytesToStrip - #17622
Merged
Merged
Conversation
…an initialBytesToStrip (#17606) Motivation: When the adjusted frame length is less than `initialBytesToStrip`, `LengthFieldBasedFrameDecoder` throws a `CorruptedFrameException` without resetting `frameLengthInt`. Every following `decode(...)` call then skips reading the length field of the next frame, sees the same short frame length again, and throws again. `frameLength` is `0` in those calls, so no bytes are skipped either. One malformed frame therefore makes every later frame on the connection fail (`Adjusted frame length (0) is less than initialBytesToStrip: ...`). The same happens on the first malformed frame if its length field and its content arrive in separate reads. All the other error paths of the decoder reset their state and go on with the next frame. This regressed in #12173, which cached the frame length in `frameLengthInt` but only reset it on the success path. Modification: - Reset `frameLengthInt` before failing, and skip the frame using `frameLengthInt` instead of the local `frameLength`, which is `0` when the length field was read by an earlier call. - Add two tests: the malformed frame in one read, and its length field and content in separate reads. Both fail without the change (with the exception above on the following valid frame) and pass with it. Result: The decoder fails the malformed frame and then decodes the following frames again. `codec-base` tests: 352, 0 failures. (cherry picked from commit c784721)
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test SummaryBuild PR / linux-x86_64-java25-adaptive build > Netty/Common
🏷️ Commit: 8ea1630 Test FailuresSingleThreadEventExecutorTest > testSuspendDoesNotRaceWithCancelledScheduledTask() (Netty/Common in Build PR / linux-x86_64-java25-adaptive build)
Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Auto-port of #17606 to 5.0
Cherry-picked commit: c784721
Motivation:
When the adjusted frame length is less than
initialBytesToStrip,LengthFieldBasedFrameDecoderthrows aCorruptedFrameExceptionwithout resettingframeLengthInt. Every followingdecode(...)call then skips reading the length field of the next frame, sees the same short frame length again, and throws again.frameLengthis0in those calls, so no bytes are skipped either. One malformed frame therefore makes every later frame on the connection fail (Adjusted frame length (0) is less than initialBytesToStrip: ...). The same happens on the first malformed frame if its length field and its content arrive in separate reads. All the other error paths of the decoder reset their state and go on with the next frame. This regressed in #12173, which cached the frame length inframeLengthIntbut only reset it on the success path.Modification:
frameLengthIntbefore failing, and skip the frame usingframeLengthIntinstead of the localframeLength, which is0when the length field was read by an earlier call.Result:
The decoder fails the malformed frame and then decodes the following frames again.
codec-basetests: 352, 0 failures.This was found by modelling the decoder's frame-length arithmetic and state in Lean 4 (a proof that every error path returns to the "new frame" state failed on this path), then reproducing it with the real class. The change was prepared with Claude Code (Claude Opus 5.5), and the commit has a
Co-Authored-Bytrailer.🤖 Generated with Claude Code