Skip to content

fix(mysql): return error instead of panic on truncated OK packet#4176

Open
cvzx wants to merge 2 commits intolaunchbadge:mainfrom
cvzx:fix/ok-packet-truncated-panic
Open

fix(mysql): return error instead of panic on truncated OK packet#4176
cvzx wants to merge 2 commits intolaunchbadge:mainfrom
cvzx:fix/ok-packet-truncated-panic

Conversation

@cvzx
Copy link
Contributor

@cvzx cvzx commented Feb 21, 2026

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.

@cvzx cvzx force-pushed the fix/ok-packet-truncated-panic branch from d0ca316 to 0ffef15 Compare February 22, 2026 00:04
Comment on lines 27 to 28
let affected_rows = buf.get_uint_lenenc();
let last_insert_id = buf.get_uint_lenenc();
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

@cvzx cvzx force-pushed the fix/ok-packet-truncated-panic branch from 53b3be5 to 33b6165 Compare February 28, 2026 00:31
Change get_uint_lenenc to return Result and validate buffer has
sufficient bytes before each read
@cvzx cvzx force-pushed the fix/ok-packet-truncated-panic branch from 33b6165 to af6fb80 Compare February 28, 2026 00:38
@cvzx cvzx requested a review from abonander February 28, 2026 15:12
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.

Rare panic in parsing of MySQL packet

2 participants