Skip to content

fix: binary protocol TIME microsecond encoding corrupts subsequent columns (#25437) - #25448

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-25437-main
Jul 3, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-25437-main

Conversation

@ck89119

@ck89119 ck89119 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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 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

Verification:

  • Focused and full frontend test suite: green
  • Go reproducible end-to-end (protocol prepared UPDATE → binary protocol readback): all read paths return correct values
  • git diff --check: passed

🤖 Generated with Claude Code

@ck89119
ck89119 requested a review from XuPeng-SH as a code owner July 3, 2026 10:08
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

…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]>
@ck89119
ck89119 force-pushed the issue-25437-main branch from b424f0d to 1f52e15 Compare July 3, 2026 10:48

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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...HEAD
  • make err-check
  • focused frontend tests for the new/related binary row cases
  • full go test -count=1 ./pkg/frontend with local macOS CGo rpath setup

CI still needs to finish, but I don't see a code-review blocker in this diff.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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...HEAD passed
  • make err-check passed
  • 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 XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.go is clean
  • git diff --check origin/main...HEAD passed
  • make err-check passed
  • 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.

@mergify
mergify Bot merged commit 5fe5e46 into matrixorigin:main Jul 3, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label Jul 3, 2026

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants