Repository navigation
fix: binary protocol TIME microsecond encoding corrupts subsequent columns (#25437) - #25448
Conversation
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? |
…lumns (matrixorigin#25437) The binary-protocol result row writer (appendTime) wrote the microsecond field as 8 bytes (appendUint64) when MySQL protocol specifies 4 bytes. This shifted every column after the TIME value by 4 bytes in the client's parser, causing VARBINARY to appear empty and BIGINT UNSIGNED to read garbage bytes. The symmetric parameter-parser bug (readTime) also failed to advance pos past the 4-byte microsecond field on length-12 TIME parameters, which would cause misparse of subsequent parameters with JDBC/C connectors. Changes: - appendTime: use appendUint32(uint32(msec)) instead of appendUint64(msec) - readTime: capture pos from ReadUint32 to advance past microsecond bytes - New UT: binary row microsecond alignment and readTime pos advancement Co-Authored-By: Claude Fable 5 <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
LGTM. The fix is narrow and matches the MySQL binary protocol layout: TIME length-12 carries sign(1)+days(4)+h/m/s(3)+microseconds(4), not an 8-byte microsecond field. The paired readTime offset fix also closes the prepared-parameter side of the same alignment bug.
I checked the affected paths from a few angles:
- binary result row encoding: TIME with nonzero micros now leaves the following column aligned
- prepared parameter decoding: len-12 TIME advances past the 4 microsecond bytes
- zero-microsecond and zero-time cases still use length 8 / 0 respectively
- negative TIME with days is covered
- datetime/timestamp already use 4-byte microseconds and are not regressed
Local checks run:
git diff --check origin/main...HEADmake err-check- focused frontend tests for the new/related binary row cases
- full
go test -count=1 ./pkg/frontendwith local macOS CGo rpath setup
CI still needs to finish, but I don't see a code-review blocker in this diff.
XuPeng-SH
left a comment
There was a problem hiding this comment.
One small change needed on the latest head (1f52e1541ec9b8a69e1f5471e6d43a25baeca29d): please run gofmt on pkg/frontend/mysql_protocol.go.
gofmt -l pkg/frontend/mysql_protocol.go pkg/frontend/mysql_protocol_test.go currently reports:
pkg/frontend/mysql_protocol.go
The functional direction still looks correct, and the latest added malformed-packet guard is good. Local checks on the latest head:
git diff --check origin/main...HEADpassedmake err-checkpassed- focused frontend tests for the changed TIME binary protocol paths passed
After formatting, I do not see another code-review blocker in this diff.
XuPeng-SH
left a comment
There was a problem hiding this comment.
LGTM on the latest head (cdcdad6ab0f9102916dca7c68c16831f553d18ef). The prior gofmt issue is fixed.
Checked again after the formatting commit:
gofmt -l pkg/frontend/mysql_protocol.go pkg/frontend/mysql_protocol_test.gois cleangit diff --check origin/main...HEADpassedmake err-checkpassed- focused frontend tests for TIME binary row alignment / readTime offset / datetime binary rows passed
The code path is narrow and the fix matches the MySQL binary protocol TIME layout: length-12 TIME uses 4 bytes for microseconds, and the prepared parameter parser now advances past those bytes with malformed-packet handling.
What type of PR is this?
Which issue(s) this PR fixes:
issue #25437
What this PR does / why we need it:
The binary-protocol result row writer (
appendTime) wrote the microsecond field as 8 bytes (appendUint64) when MySQL protocol specifies 4 bytes. This shifted every column after the TIME value by 4 bytes in the client's parser, causing VARBINARY to appear empty and BIGINT UNSIGNED to read garbage bytes (4771354034768445440= the hex string lenenc marker).The symmetric parameter-parser bug (
readTime) also failed to advancepospast the 4-byte microsecond field on length-12 TIME parameters, which would cause misparse of subsequent parameters with JDBC/C connectors.Changes:
appendTime: useappendUint32(uint32(msec))instead ofappendUint64(msec)readTime: captureposfromReadUint32to advance past microsecond bytesreadTimepos advancementVerification:
git diff --check: passed🤖 Generated with Claude Code