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 — Length field based frame decoder can be optimized by AbcCreatorDeep · Pull Request #12173 · netty/netty

Conversation

@AbcCreatorDeep

@AbcCreatorDeep AbcCreatorDeep commented Mar 15, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Motivation:

LengthFieldBasedFrameDecoder. decode(ChannelHandlerContext ctx, ByteBuf in) method,Can be optimized -So we keep frameLengthInt in instance variable to avoid unnecessary calculations , When there is not enough data in the buffer, current data frame's frameLength does not need to be recalculated at the next decoding.

Modification:

Add an instance variable to avoid unnecessary calculations : private int frameLengthInt = -1

Result:

Fixes #12171.

Sorry, something went wrong.

Uh oh!

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

All reactions
黄俊 added 2 commits March 15, 2022 17:40
黄俊
Update LengthFieldBasedFrameDecoder.java
60a4879
黄俊
Update LengthFieldBasedFrameDecoder.java
9a36e35
normanmaurer
normanmaurer reviewed Mar 15, 2022
View reviewed changes
Comment thread codec/src/main/java/io/netty/handler/codec/LengthFieldBasedFrameDecoder.java Resolved

Uh oh!

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

Comment thread codec/src/main/java/io/netty/handler/codec/LengthFieldBasedFrameDecoder.java Resolved

Uh oh!

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

normanmaurer added 2 commits March 15, 2022 11:38
@normanmaurer
Update codec/src/main/java/io/netty/handler/codec/LengthFieldBasedFra…
9740469
…meDecoder.java
@normanmaurer
Update codec/src/main/java/io/netty/handler/codec/LengthFieldBasedFra…
0c0c120
…meDecoder.java
@AbcCreatorDeep

AbcCreatorDeep commented Mar 15, 2022

Copy link
Copy Markdown
Author

Man, is this PR possible to get accepted?

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer

normanmaurer commented Mar 15, 2022

Copy link
Copy Markdown
Member

sure... Lets wait for the CI to finish

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.76.Final milestone Mar 15, 2022
@normanmaurer

normanmaurer commented Mar 15, 2022

Copy link
Copy Markdown
Member

@NickleHuang can you please sign our ICLA: https://netty.io/s/icla

All reactions

Sorry, something went wrong.

Uh oh!

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

@AbcCreatorDeep

AbcCreatorDeep commented Mar 15, 2022

Copy link
Copy Markdown
Author

@NickleHuang can you please sign our ICLA: https://netty.io/s/icla

Done

All reactions

Sorry, something went wrong.

Uh oh!

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

@normanmaurer
normanmaurer merged commit 824a0b8 into netty:4.1 Mar 15, 2022
@normanmaurer

normanmaurer commented Mar 15, 2022

Copy link
Copy Markdown
Member

@NickleHuang thanks... merged!

All reactions

Sorry, something went wrong.

Uh oh!

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

normanmaurer added a commit that referenced this pull request Mar 15, 2022
黄俊 @normanmaurer
Length field based frame decoder can be optimized (#12173)
457faee
Motivation:

LengthFieldBasedFrameDecoder.decode(ChannelHandlerContext ctx, ByteBuf in) methodcan be optimized -So we keep frameLengthInt in instance variable to avoid unnecessary calculations .

Modification:

Add an instance variable to avoid unnecessary calculations

Result:

Fixes #12171.

Co-authored-by: Norman Maurer <[email protected]>
raidyue pushed a commit to raidyue/netty that referenced this pull request Jul 8, 2022
黄俊 @normanmaurer 夏无影
Length field based frame decoder can be optimized (netty#12173)
110bcaf
Motivation:

LengthFieldBasedFrameDecoder.decode(ChannelHandlerContext ctx, ByteBuf in) methodcan be optimized -So we keep frameLengthInt in instance variable to avoid unnecessary calculations .

Modification:

Add an instance variable to avoid unnecessary calculations

Result:

Fixes netty#12171. 


Co-authored-by: Norman Maurer <[email protected]>
franz1981 pushed a commit to franz1981/netty that referenced this pull request Aug 22, 2022
黄俊 @normanmaurer @franz1981
Length field based frame decoder can be optimized (netty#12173)
18428ef
Motivation:

LengthFieldBasedFrameDecoder.decode(ChannelHandlerContext ctx, ByteBuf in) methodcan be optimized -So we keep frameLengthInt in instance variable to avoid unnecessary calculations .

Modification:

Add an instance variable to avoid unnecessary calculations

Result:

Fixes netty#12171. 


Co-authored-by: Norman Maurer <[email protected]>
@allthingssecurity allthingssecurity mentioned this pull request Sep 24, 2026
Reset LengthFieldBasedFrameDecoder state when the frame is shorter than initialBytesToStrip #17606
Merged
normanmaurer pushed a commit that referenced this pull request Sep 25, 2026
@allthingssecurity
Reset LengthFieldBasedFrameDecoder state when the frame is shorter th…
c784721
…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.
This was referenced Sep 25, 2026
Auto-port 4.1: Reset LengthFieldBasedFrameDecoder state when the frame is shorter than initialBytesToStrip #17621
Merged
Auto-port 5.0: Reset LengthFieldBasedFrameDecoder state when the frame is shorter than initialBytesToStrip #17622
Merged
normanmaurer pushed a commit that referenced this pull request Sep 25, 2026
@netty-project-bot @allthingssecurity
Auto-port 4.1: Reset LengthFieldBasedFrameDecoder state when the fram…
8aee85d
…e is shorter than initialBytesToStrip (#17621)

Auto-port of #17606 to 4.1
Cherry-picked commit: c784721

---
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.

Co-authored-by: allthingssecurity <[email protected]>
normanmaurer added a commit that referenced this pull request Sep 25, 2026
@netty-project-bot @allthingssecurity @normanmaurer
Auto-port 5.0: Reset LengthFieldBasedFrameDecoder state when the fram…
2329198
…e is shorter than initialBytesToStrip (#17622)

Auto-port of #17606 to 5.0
Cherry-picked commit: c784721

---
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.

---------

Co-authored-by: allthingssecurity <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
@netty-project-bot @allthingssecurity @lltopk
Auto-port 4.1: Reset LengthFieldBasedFrameDecoder state when the fram…
ee2ba98
…e is shorter than initialBytesToStrip (netty#17621)

Auto-port of netty#17606 to 4.1
Cherry-picked commit: c784721

---
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 netty#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.

Co-authored-by: allthingssecurity <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer left review comments

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.76.Final

Development

Successfully merging this pull request may close these issues.

LengthFieldBasedFrameDecoder Class Can be optimized

Uh oh!

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

2 participants

@AbcCreatorDeep @normanmaurer
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.