Fix TCP message handling panics and oversized allocations - #3889
Open
Aditya30ag wants to merge 3 commits into
Open
Fix TCP message handling panics and oversized allocations#3889Aditya30ag wants to merge 3 commits into
Aditya30ag wants to merge 3 commits into
Conversation
Aditya30ag
marked this pull request as draft
August 12, 2026 09:36
Aditya30ag
marked this pull request as ready for review
August 12, 2026 09:50
domenukk
reviewed
Aug 12, 2026
| len += 4; | ||
| log::debug!("TCP Manager - len = {len:?}"); | ||
|
|
||
| if len > TCP_MAX_MSG_LEN { |
Member
There was a problem hiding this comment.
if you want this to be 100% correct you also should check for size before adding 4 to the len (since at this point it could already have overflown for MAX_INT)
Contributor
Author
There was a problem hiding this comment.
Good catch. I changed the length calculation to use checked_add(4) before applying the maximum message size check, so the addition is now protected against integer overflow.
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.
Summary
This PR improves robustness of TCP message handling by preventing panics and unsafe allocations when receiving malformed input.
Changes
expect()/panic paths with proper error propagation.Previously, malformed TCP input could:
These changes ensure invalid input results in an error instead of crashing the process.
Testing
Tested with: