Repository navigation
fix(protocol): read 3-byte length-encoded ints without panicking - #200
Open
AntonPates wants to merge 1 commit into
Open
AntonPates wants to merge 1 commit into
AntonPates wants to merge 1 commit into
Conversation
readLengthEncodedInt decoded the 0xFD prefix with binary.LittleEndian.Uint32(b[1:4]), which needs 4 bytes but gets 3 and always panics. Clients send every string/BLOB parameter of 64 KiB..16 MiB in COM_STMT_EXECUTE with that prefix, so one such INSERT crashed the whole server process (index out of range [3] with length 3). Decode the three bytes explicitly and add tests for every prefix and for parseParamValue with a 70000-byte BLOB. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UToh6jDBmKGsVgdjX2Cbq8
This branch has not been deployed
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.
Fixes #199.
Problem
readLengthEncodedIntdecoded the0xFDprefix (a 3-byte little-endian length) withbinary.LittleEndian.Uint32(b[1:4]).Uint32needs 4 bytes, so this always panicked. Clients send every string/BLOB parameter of 64 KiB..16 MiB inCOM_STMT_EXECUTEwith that prefix, so one suchINSERTcrashed the whole server process (index out of range [3] with length 3).Change
protocol/server.go: decode the three bytes explicitly:uint64(b[1]) | uint64(b[2])<<8 | uint64(b[3])<<16.protocol/length_encoded_int_test.go:readLengthEncodedIntcovering every prefix, including the0xFDboundaries (65,536 and 16,777,215), an exact 4-byte slice and truncated input;parseParamValuewith a 70,000-byte BLOB.Testing
masterwith the same panic as in production, and pass with the fix.go test ./protocol/passes.🤖 Generated with Claude Code
https://claude.ai/code/session_01UToh6jDBmKGsVgdjX2Cbq8