Skip to content

[Bug]: FROM_BASE64 appends zero bytes to valid padded input #28208

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

#15904 was closed and covered invalid input plus empty input. It did not cover valid padded input returning extra bytes.

Branch Name

main

Commit ID

e7bb0572235ec4bac81eb098eb0ad8900f0065ab

Other Environment Information

  • Local standalone MatrixOne; MySQL text protocol
  • Reference: MySQL 8.3.0

Actual Behavior

FROM_BASE64() returns the decoder buffer capacity instead of the decoded length, appending zero bytes to valid padded input:

SELECT HEX(FROM_BASE64('YQ=='));
-- MatrixOne: 610000
-- MySQL:    61

SELECT HEX(FROM_BASE64(CONCAT('YQ==', CHAR(10))));
-- MatrixOne: 610000
-- MySQL:    61

Spaces and tabs within Base64 text are also rejected as NULL although MySQL ignores whitespace:

SELECT HEX(FROM_BASE64('Y Q = ='));
-- MatrixOne: NULL
-- MySQL:    61

Constant and column-expression forms reproduce identically in three runs.

Expected Behavior

Only bytes actually written by the decoder must be returned, and whitespace accepted by MySQL's Base64 decoder must be ignored.

Steps to Reproduce

SELECT HEX(FROM_BASE64('YQ=='));
SELECT HEX(FROM_BASE64(CONCAT('YQ==', CHAR(10))));
SELECT HEX(FROM_BASE64('Y Q = ='));

Additional information

FromBase64 allocates base64.StdEncoding.DecodedLen(len(data)), calls Decode, ignores the returned byte count, and appends the entire allocation. For YQ==, capacity is 3 while decoded length is 1.

Activity

  1. added this to the MO-202609 milestone on Sep 5, 2026
  2. added
    kind/bug
    on Sep 5, 2026
  3. added theissue type on Sep 5, 2026
  4. self-assigned this
    on Sep 5, 2026
  5. added a commit that references this issue on Sep 8, 2026
    f72ca9e
  6. Ariznawlll commented on Sep 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试环境:MatrixOne 最新 main f72ca9efbeb3a7c673701e4a135cc6670c33cfde,本地单机服务(MySQL 协议 6001)。

    测试步骤:

    1. 执行带填充符的 Base64 YQ==。
    2. 执行带换行的 Base64 拼接。
    3. 执行包含空格的 Base64。
    4. 同时验证表列表达式,并重复执行 3 次。

    测试结果:三类输入均返回实际解码字节 61,未再追加 00,空白字符被正确忽略;3/3 结果一致。

    结论:问题已修复。修复提交 #28360(f72ca9efbeb)已包含在当前 main;对应 MOTR 用例已加入 PR #147(https://github.com/matrixorigin/motr/pull/147),MOTR 定向运行通过。

  7. added 3 commits that reference this issue on Sep 17, 2026
    864e7c6
    6df4cb0
    5d7fbb4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions