fix(mysql): return error instead of panic on truncated OK packet#4176
Open
cvzx wants to merge 2 commits intolaunchbadge:mainfrom
Open
fix(mysql): return error instead of panic on truncated OK packet#4176cvzx wants to merge 2 commits intolaunchbadge:mainfrom
cvzx wants to merge 2 commits intolaunchbadge:mainfrom
Conversation
d0ca316 to
0ffef15
Compare
abonander
requested changes
Feb 27, 2026
Comment on lines
27
to
28
| let affected_rows = buf.get_uint_lenenc(); | ||
| let last_insert_id = buf.get_uint_lenenc(); |
Collaborator
There was a problem hiding this comment.
I don't want to move the goalposts too much, but it seems like these fields should at least be covered by the length check too.
In the long run we should probably ban use of bytes::Buf methods and instead write our own that return Result.
Contributor
Author
There was a problem hiding this comment.
Checking get_uint_lenenc calls is a bit trickier since the method advances a variable number of bytes depending on the prefix. I've changed its signature to return Result and added remaining-bytes checks inside the method, propagating with ? at all call sites.
If this approach is good, I could follow up with a separate PR that wraps the other panicking bytes::Buf methods in the same way.
53b3be5 to
33b6165
Compare
Change get_uint_lenenc to return Result and validate buffer has sufficient bytes before each read
33b6165 to
af6fb80
Compare
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.
Does your PR solve an issue?
fixes #4139
Is this a breaking change?
No. This changes a panic into a returned
Err(Protocol(...)), which callers already handle. The connection pool will gracefully discard the bad connection instead of crashing the tokio worker thread.