Skip to content

[Bug]: COM_STMT_EXECUTE date-family decoding accepts or panics on truncated bodies #25756

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

e538e203ad47ebf0506a424fe93aed61290c4061

Actual Behavior

Binary-protocol DATE, DATETIME, and TIMESTAMP parameter decoding does not validate that the declared temporal body is present before indexing it.

readDate, readDateTime, and readTimestamp perform unchecked indexing and ignore failed integer reads. A white-box short-packet test supplies every body length from zero through declared-length minus one for DATE(4), DATETIME(7), and TIMESTAMP(11). On latest main, malformed packets are either silently accepted with a nil error or panic with an index-out-of-range error.

The TIME(8)/TIME(12) bounds handling and TIME(12) position advancement originally included in this issue are already fixed on main by 5fe5e46fc9. A valid TIME(12) followed by another parameter now decodes correctly. This issue is therefore narrowed to the date-family helpers.

Expected Behavior

Any DATE, DATETIME, or TIMESTAMP body shorter than its declared binary-protocol length must return a malformed-packet error without panicking or consuming bytes outside that parameter.

Steps to Reproduce

  1. Prepare select ?.
  2. Bind each of DATE(4), DATETIME(7), and TIMESTAMP(11).
  3. For each type, provide every body length from zero through declared-length minus one.
  4. Assert parsing does not panic and returns an error.
  5. On main@e538e203a, the test observes both nil errors and index-out-of-range panics.

Relevant code

  • pkg/frontend/mysql_protocol.go:1021-1044
  • pkg/frontend/mysql_protocol.go:1070-1076
  • pkg/frontend/mysql_protocol.go:1122-1136

Activity

  1. added
    kind/bug
    on Jul 15, 2026
  2. changed the title [-][Bug]: COM_STMT_EXECUTE temporal decoding panics on truncation and misaligns TIME(12)[/-] [+][Bug]: COM_STMT_EXECUTE date-family decoding accepts or panics on truncated bodies[/+] on Jul 15, 2026
  3. Ariznawlll commented on Jul 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    main 分支复核

    • 测试基线:当轮最新 origin/main@e538e203ad47ebf0506a424fe93aed61290c4061
    • 测试过程/用例:分别对 DATE(4)、DATETIME(7)、TIMESTAMP(11) 构造从 0 到声明长度减 1 的全部截断 body;断言不得 panic 且必须返回错误。
    • 实际结果:仍同时存在“错误返回 nil”和“数组越界 panic”。
    • 范围纠正:TIME(8/12) 的边界与 TIME(12) position 推进已由 5fe5e46fc9 修复,因此标题和正文已收窄为 date-family 问题。
    • 结论:收窄后的问题仍可复现,issue 有效。
  4. added theissue type on Jul 15, 2026
  5. added this to the MO-202607 milestone on Jul 15, 2026
  6. daviszhen commented on Sep 21, 2026

    @daviszhen
    Contributor

    本地 Docker 实测复核(2026-09-21):使用从当时最新 matrixorigin/main@df41cc24fc88fefab35151b494faa928c55eacb8 构建的 mo-service,直连 CN 的 MySQL 协议端口发送原始报文;已核对容器运行进程与构建产物的 SHA-256 一致。

    先用 COM_STMT_PREPARE 准备 select ?,再分别构造 DATE(4)、DATETIME(7)、TIMESTAMP(11) 的每一种截断 body(实际长度 0 到声明长度减 1,共 22 个 COM_STMT_EXECUTE)。22/22 均收到 MySQL ERR 20301:invalid input: mysql protocol error, malformed packet。CN 日志未发现越界 panic;测试后的新连接与 COM_PING 仍正常。

    结论:此 issue 描述的 date-family 截断问题在上述 main 提交上已无法复现。修复代码见 e2c5dc0 / PR #25750 的 temporal body 长度检查。本次验证范围是这 22 个截断输入,不代表覆盖其他参数类型。

  7. Ariznawlll commented on Sep 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 日期:2026-09-22
    • 分支:main
    • MatrixOne commit:3727c5c5436ca136d7b0312f75bc223a11692a85
    • 部署:本地单机,1 Log / 1 TN / 1 CN

    原问题验证

    COM_STMT_EXECUTE 对 DATE、DATETIME、TIMESTAMP 的截断二进制参数均返回协议错误,不再接受非法值或触发 panic。

    Happy Path 覆盖

    通过原始 MySQL handshake、COM_STMT_PREPARE 与 COM_STMT_EXECUTE 完成合法预处理语句生命周期,并在每次异常后以 COM_PING 验证连接可继续使用。

    Unhappy Path 覆盖

    覆盖 DATE(合法长度 4)、DATETIME(合法长度 7)、TIMESTAMP(合法长度 11)的全部截断长度,单轮共 66 个畸形包,全部返回 ERR。

    白盒验证

    测试直接构造 wire packet,不经过驱动的参数长度校验,能够命中服务端 date-family 解码边界;每个错误后检查 session 健康状态。

    回归测试

    新增 script/14_issue_regression/issue_25743_25744_25756_protocol_bounds.go 及同名 .sh 入口,已提交至 motr#199。

    测试证据

    协议场景连续执行 3 轮;本次新增 7 个 case 共执行 21 次,结果为 21/21 通过。14_issue_regression 整套执行时该场景也通过。MOTR 当前未为该分支上报远端 checks。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

deferredkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions