Skip to content

[Bug]: CAST AS CHAR without a length silently truncates large strings #32336

Open

Description

@XuPeng-SH

Actual behavior

CAST(expr AS CHAR) without an explicit length silently truncates a 100,000-byte string to 65,535 bytes. The input itself is not truncated. This can corrupt or invalidate large application payloads read through a cast.

Minimal SQL reproduction

SELECT
  LENGTH(CONCAT(REPEAT('a', 50000), REPEAT('b', 50000))) AS input_bytes,
  LENGTH(CAST(CONCAT(REPEAT('a', 50000), REPEAT('b', 50000)) AS CHAR)) AS cast_bytes;
Server input_bytes cast_bytes
MatrixOne 8.0.30-MatrixOne-v4.2.1 100000 65535
MySQL 8.0.46 100000 100000

The MatrixOne instance used image matrixorigin/matrixone@sha256:c95d1b468e3fc5f4f2b377da14f4601e7efefa6eb143758636d60114a5bbb436. Both queries were executed over the MySQL protocol. The same truncation was also observed when reading a 100,000-byte stored LONGTEXT column.

Expected behavior

Without a specified length, preserve the complete string, as the MySQL control does. MySQL's CAST documentation describes length inference and widening for large strings.

Impact and workaround

An Astra Edge dispatch result can be larger than 64 KiB. Casting its LONGTEXT result column to CHAR truncates the result before the client reads it. Reading the LONGTEXT column directly preserves the complete value and avoids the extra cast.

Related: #28103 recorded the same 65,535-byte behavior for CAST(... AS CHAR) as a control while diagnosing SHA2; this issue isolates the CAST compatibility problem itself.

Activity

  1. MatrixAdventurer commented on Nov 7, 2026

    @MatrixAdventurer
    Contributor

    分级建议:s1/P1。理由:无长度 CAST 静默截断,与 MySQL 权威语义背离,属正确性缺陷,可能损坏上层读取的载荷;正文有最小 SQL 对照,非崩溃类。
    模块/目录:pkg/sql 表达式层 CAST→CHAR 的长度推断(建议在类型系统/表达式求值侧修复)。
    疑似重复:未发现独立跟踪单(正文引用的 #28103 记录同一 65535 现象,仅作对照组)。
    建议负责人:尚无 assignee;正文作者 XuPeng-SH 已完成对照,建议交内核类型/表达式方向评审。
    本操作由LW授权的MOI智能体提交

  2. Ariznawlll commented on Nov 9, 2026

    @Ariznawlll
    Collaborator

    结论

    测试不通过。当前 main 的无长度 CHAR CAST 仍会在 CONCAT 输入上静默截断 100000 字节字符串。

    关键证据

    • 版本:main@c99234dcf4c94d1ff9d372917cd35041f1a3a682,隔离本地 CN,运行时 git_version() 为 c99234dcf4。
    • 3 次执行 CAST(CONCAT(REPEAT('a',50000),REPEAT('b',50000)) AS CHAR),输入长度均为 100000,结果长度均为 65535;相邻控制 CAST(REPEAT('a',100000) AS CHAR) 返回 100000。
    • 失败只涉及 CONCAT 表达式的宽度/CAST 路径;没有把 JSON→CHAR 结果混作本 issue 的唯一证据。

    待解决点

    • 本轮未验证存储 LONGTEXT 列读取或更复杂的 CONCAT 嵌套。
  3. added
    severity/s0
    ai-easy
    and removed on Nov 9, 2026
  4. XuPeng-SH commented on Nov 20, 2026

    @XuPeng-SH
    ContributorAuthor

    Administrative consolidation of #32374 into this issue. This is not a fix claim.

    Additional acceptance coverage retained from #32374:

    • JSON CAST(... AS CHAR) must preserve values larger than 65,535 bytes. A 100,000-byte input must remain complete and valid JSON, or produce an explicit error if a limit applies; silent truncation is not acceptable.
    • The existing LONGTEXT and large-string acceptance cases remain in scope.

    Assignee retained: matrix-meow.

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

Metadata

Metadata

Assignees

Labels

ai-easyseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions