Skip to content

[Compatibility]: INET6_NTOA formats IPv4-compatible IPv6 tails as hexadecimal #28389

Closed

Description

@Ariznawlll

MatrixOne version

Latest main at f72ca9efbeb3a7c673701e4a135cc6670c33cfde. MySQL control: 8.3.0.

What is different

INET6_NTOA() formats IPv4-compatible IPv6 addresses (::IPv4) using the final 32 bits as two hexadecimal hextets. MySQL uses dotted-decimal IPv4 notation for this address class.

This is distinct from #28216: the IPv4-compatible input remains a correct 16-byte value and is classified correctly; only INET6_NTOA text formatting differs. #28216 covers IPv4-mapped (::ffff:IPv4) values that are collapsed to four bytes and misclassified.

Reproduction

SELECT INET6_NTOA(UNHEX('0000000000000000000000007F000001'));
SELECT INET6_NTOA(UNHEX('000000000000000000000000C0000201'));
SELECT INET6_NTOA(UNHEX('000000000000000000000000FFFFFFFF'));

SELECT INET6_NTOA(INET6_ATON('::192.0.2.1'));
SELECT INET6_NTOA(INET6_ATON('::c000:201'));

MatrixOne returns:

::7f00:1
::c000:201
::ffff:ffff
::c000:201
::c000:201

MySQL 8.3 returns:

::127.0.0.1
::192.0.2.1
::255.255.255.255
::192.0.2.1
::192.0.2.1

The constant, table-column, round-trip, and SQL PREPARE/EXECUTE paths were reproduced identically in three runs per engine.

Controls

  • HEX(INET6_ATON('::192.0.2.1')) is 000000000000000000000000C0000201 in both engines.
  • IS_IPV6('::192.0.2.1') and IS_IPV4_COMPAT(INET6_ATON('::192.0.2.1')) both return 1 in both engines.
  • Ordinary IPv6 addresses, ::, ::1, and IPv6 addresses with a non-compatible embedded IPv4 tail (for example 2001:db8::192.0.2.1) use matching canonical hexadecimal output.

Root cause

For 16-byte input, MatrixOne sends non-mapped values directly through Go's net.IP.String() (Inet6Ntoa). That formatter emits ::c000:201; it does not implement MySQL's dotted-decimal rendering for IPv4-compatible IPv6 values.

Expected behavior

INET6_NTOA() should render IPv4-compatible IPv6 addresses as ::a.b.c.d, matching MySQL, while preserving the existing canonical output for ordinary IPv6 and 4-byte IPv4 inputs.

Activity

  1. added this to the MO-202609 milestone on Sep 8, 2026
  2. added theissue type on Sep 8, 2026
  3. self-assigned this
    on Sep 8, 2026
  4. XuPeng-SH commented on Sep 8, 2026

    @XuPeng-SH
    Contributor

    已完成修复并提交 PR #28447:#28447。

    Root cause 已确认:16 字节输入的非 mapped 地址原先统一交给 Go net.IP.String(),它只输出十六进制压缩形式,不实现 MySQL 对 IPv4-compatible 地址的点分十进制尾部格式化。

    修复严格对齐 MySQL 的边界规则:仅当前 6 个 IPv6 hextet 为 0 且第 7 个 hextet 非 0 时输出 ::a.b.c.d。因此:

    • ::192.0.2.1 -> ::192.0.2.1
    • ::255.255.255.255 -> ::255.255.255.255
    • ::1、::100 保持 ::1、::100
    • IPv4-mapped 地址、普通 IPv6、4 字节 IPv4、NULL、非法长度行为保持不变

    验证证据:

    • 最新 origin/main 基线真实服务仍复现 ::7f00:1、::c000:201、::ffff:ffff;修复服务得到 MySQL 兼容结果。
    • MySQL 8.4 源码 sql/item_inetfunc.cc 的 ipv6_to_str() 对照确认上述精确边界。
    • 单测、race 目标测试、pkg/sql/plan/function 与 pkg/sql/plan 测试通过。
    • 新增 BVT 14/14 通过,覆盖常量、表达式回环、混合列向量、NULL、mapped/普通 IPv6 及低尾部边界。
    • molint 无发现,针对模块的 golangci-lint 为 0 issues。

    该修复仅影响 INET6_NTOA 文本格式化,不涉及存储、网络、查询计划或 INET6_ATON 二进制编码。

  5. added a commit that references this issue on Sep 9, 2026
    45a1dbd
  6. Ariznawlll commented on Sep 9, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:a9d3b8b857c44f1249e682c91d4d62a914eb7d20
    • 环境:本地单机 MatrixOne,2026-09-09。

    原问题验证

    验证 INET6_NTOA 对 IPv4-compatible IPv6 地址不再错误压缩,并保持其他地址格式不回归。

    Happy Path 覆盖

    • ::127.0.0.1、::192.0.2.1 均返回点分 IPv4-compatible 格式;
    • 普通 IPv6、loopback、IPv4 输入均返回预期文本,连续 3 轮一致。

    Unhappy Path 覆盖

    本 issue 的异常分支是格式错误压缩而非 SQL 参数拒绝;已以普通 IPv6/loopback/IPv4 作为非 compatible 控制组,确认未被错误套用 compatible 格式。

    白盒验证

    不适用:通过函数输出覆盖各地址族分支。

    回归测试

    • 已加入 MOTR PR #152:suites/14_issue_regression/t/issue_28389_28387_network_return_types.test。
    • --record --repeat 3 和非 record --repeat 3 均通过;PR 共 21/21 用例、321/321 条语句成功。

    测试证据

    compatible 与非 compatible 控制组均重复 3 次。

    测试结论

    测试通过。

  7. added 3 commits that reference this issue on Sep 17, 2026
    243b054
    3cf755d
    65b809b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions