Skip to content

[Bug]: truncated COM_STMT_CLOSE and COM_STMT_RESET packets enter panic recovery #25744

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

Branch Name

main-based checkout (main)

Commit ID

e538e203ad47ebf0506a424fe93aed61290c4061

Actual Behavior

The COM_STMT_CLOSE and COM_STMT_RESET branches decode a statement ID with binary.LittleEndian.Uint32(data[0:4]) without first checking len(data) >= 4.

A packet with 0-3 bytes panics with slice bounds out of range. The top-level recovery prevents the process from crashing, but it returns a non-nil Go error and constructs a response for COM_QUERY, so the protocol-level response is associated with the wrong command.

White-box tests using a three-byte payload reproduce the panic/recovery path for both commands.

Expected Behavior

Truncated COM_STMT_CLOSE and COM_STMT_RESET packets should be validated before decoding and return a normal protocol error response for the original command without entering panic recovery.

Steps to Reproduce

For each of COM_STMT_CLOSE and COM_STMT_RESET:

  1. Create a minimal frontend session and command executor.
  2. Call ExecRequest with payload []byte{1, 2, 3}.
  3. Observe the recovered slice bounds out of range error and the response command being COM_QUERY.

Relevant code

  • pkg/frontend/mysql_cmd_executor.go: ExecRequest COM_STMT_CLOSE branch
  • pkg/frontend/mysql_cmd_executor.go: ExecRequest COM_STMT_RESET branch

Activity

  1. added
    kind/bug
    on Jul 15, 2026
  2. Ariznawlll commented on Jul 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    main 分支复核

    • 测试基线:当轮最新 origin/main@e538e203ad47ebf0506a424fe93aed61290c4061
    • 测试过程/用例:对 COM_STMT_CLOSE 与 COM_STMT_RESET 的 payload 长度 0、1、2、3 做最小长度递减测试;期望正常返回 malformed-packet 错误且不触发 panic recovery。
    • 实际结果:两条命令的所有短包都进入 panic recovery。
    • 结论:已在该 main 基线确认仍可复现,issue 有效。
  3. added theissue type on Jul 15, 2026
  4. added this to the MO-202607 milestone on Jul 15, 2026
  5. daviszhen commented on Sep 21, 2026

    @daviszhen
    Contributor

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

    分别对 COM_STMT_CLOSE、COM_STMT_RESET 发送 payload 长度 0、1、2、3 的报文,共 8 个用例。8/8 均收到 MySQL ERR 20101,错误文本分别为 invalid COM_STMT_CLOSE packet 与 invalid COM_STMT_RESET packet;未见 slice bounds out of range / panic 日志,测试后的新连接与 COM_PING 仍正常。

    结论:此 issue 描述的短包进入 panic recovery 的问题在上述 main 提交上已无法复现。对应的 len(data) < 4 检查由 e2c5dc0 / PR #25750 引入。

  6. Ariznawlll commented on Sep 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

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

    原问题验证

    截断的 COM_STMT_CLOSE 与 COM_STMT_RESET 数据包均返回 ERR,不再进入 panic recovery。

    Happy Path 覆盖

    完成原始 MySQL handshake 与 statement 生命周期,并在每个异常响应后以 COM_PING 验证连接持续可用。

    Unhappy Path 覆盖

    覆盖两类命令 payload 长度 0、1、2、3 的截断形式,单轮共 24 个畸形包,全部返回 ERR。

    白盒验证

    测试直接构造 wire packet,不经过驱动对 statement id 长度的校验,可直接命中服务端 COM_STMT_CLOSE/RESET 解码边界。

    回归测试

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