Repository navigation
Conversation
…anicking readStringLenEnc converted a client-supplied uint64 length to int before the bounds check, so a length above MaxInt64 became negative, passed the check and panicked on the slice (COM_STMT_EXECUTE string params). readCountOfBytes had the same negative-count hole. Compare in uint64 and reject negative counts. Fixes matrixorigin#29859 Signed-off-by: MatrixAdventurer <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
There was a problem hiding this comment.
APPROVE on 14fcebc4fe02de4ce796494c1167f3e2bc4a14c3, base/merge-base 4022729da24d71b082c22b52aaed3faba2b77ea5. Direct deep review; no subagents or product edits. No blocking finding in this scoped fix.
The design fixes the existing byte-reader owner rather than adding a second packet validator. readStringLenEnc compares the unsigned length against remaining bytes before int conversion, which proves the later addition/slice safe. readCountOfBytes checks count and position before subtraction; zero-length-at-end and exact remaining-length reads remain valid. Both changes use constant-time bounds checks, with no new allocation, copy, state or execution path on valid prepared/TP traffic.
I traced callers in COM_STMT_EXECUTE, COM_CHANGE_USER, long-data and handshake auth-response parsing. Their failed-read checks return the existing malformed/error path before publishing parameter/session state. A negative offset to readIntLenEnc is not supplied by these network entry points; I did not manufacture an unreachable helper call as a finding. The patch does not claim a complete audit of every handshake field.
Evidence: the new overflow UT and existing length-prefix tests pass. I additionally extended the existing real wire-loop fixture with the exact overflowing VAR_STRING execute packet: the server returns a malformed-packet error without panic text, preserves the previous prepared parameter types/value, releases params, handles PING, and executes subsequent valid binds on the same connection; fixture shutdown passes. Four selected test roots pass. This probe uses the real packet/routine loop with the existing bounded net.Pipe fixture, not a recreated parser. Source overlays use this exact production file and the original wire test on a native-compatible checkout; all production differences to this head are restored, and the probe is not a delivered source modification. Exact-head Linux UT/SCA CI is green; the author's real-service binary execute and prepare-BVT evidence provides additional coverage, not a claim that handshake was tested on the wire.
Accounting: implementation +7/-3; focused tests +56/-0; documentation0. The small new test preserves valid empty/nonempty and exact-end controls and rejects both huge and truncated lengths. No redundant fixture/framework, retired path or prior substantive comment was found.
Post-submission head verification: Mergify merged main into this branch, moving the head to da2384fe872f83889eb0e3dd4e1ac4f7d06e399c and the base to 03c34f837b1b399587e9d7e7e2f64a92010806e3. GitHub reassociated this review with the new head. I fetched and compared both versions: the PR diff against its new base is byte-for-byte identical to the reviewed diff against4022729; both changed frontend file blobs are identical. The imported main changes concern idxcron identifier quoting and DDL test coverage, with no change to the reviewed protocol-reader/caller/wire-test closure. The analysis and selected wire evidence above are therefore reused for this exact current content; they were executed on the original reviewed production closure, not rerun or relabeled as new-head CI. Approval remains applicable.
Merge Queue Status
This pull request spent 12 minutes 9 seconds in the queue, with no time running CI. ReasonPull request #29860 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Waiting for any of
All conditions
Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #29859
Fixes #29859
What this PR does / why we need it:
readStringLenEncconverted the client-supplied length-encodeduint64tointbefore checking it against the packet. A length aboveMaxInt64(e.g.fe 30 30 30 30 30 30 30 b3) became negative, passedpos+sLength-1 >= len(data), and the slice panicked.readCountOfByteshad the same hole for negative counts; the handshake auth-response length goes through that path withint(l).Fix (1 file):
readStringLenEnccompares the length asuint64against the remaining bytes before converting.readCountOfBytesrejects negative counts and out-of-range positions.ok == falseintoinvalid input: mysql protocol error, malformed packet.Verification
Unit tests:
TestReadLenEncRejectsOverflowingLengthpanics on main and passes with the fix.go test ./pkg/frontend/passes, andgo vetis clean.End-to-end setup: built
mo-servicefrom main (d7752ff) and from this branch, ran each single-node (-launch etc/launch/launch.toml), and sent raw protocol packets with PyMySQL. The client preparedSELECT ?, then sentCOM_STMT_EXECUTEwith the issue's body00 01 00 00 00 00 01 00 00 fe 30 30 30 30 30 30 30 b3, then ranSELECT 1on the same connection.internal error: panic runtime error: slice bounds out of range [:-5534870958513311674]+ full Go stack trace returned to the clientinvalid input: mysql protocol error, malformed packetSELECT 1afterwards on the same connection'hi'BVT: mo-tester
test/distributed/cases/preparegave 3336 total / 0 failed on this build.The handshake auth-response path is covered by the
readCountOfBytesguard and the unit test, but I didn't exercise it on the wire.