Skip to content

[Bug]: INET_NTOA wraps out-of-range integers into IPv4 addresses #28215

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

#23040 was the closed implementation request; no issue covers out-of-range handling.

Branch Name

main

Commit ID

e7bb0572235ec4bac81eb098eb0ad8900f0065ab

Other Environment Information

  • Local standalone MatrixOne; reference MySQL 8.3.0

Actual Behavior

INET_NTOA() truncates every argument to its low 32 bits instead of rejecting values outside the IPv4 range:

SELECT INET_NTOA(-1), INET_NTOA(4294967296),
       INET_NTOA(18446744073709551615);
-- MatrixOne: 255.255.255.255, 0.0.0.0, 255.255.255.255
-- MySQL:    NULL, NULL, NULL

The same values in a BIGINT column produce the same result in three runs.

Expected Behavior

Negative values and values greater than 4294967295 must return NULL. They must not wrap modulo 2^32 into a different valid address.

Steps to Reproduce

SELECT INET_NTOA(-1);
SELECT INET_NTOA(4294967296);
SELECT INET_NTOA(18446744073709551615);

Additional information

Every integer overload currently converts through uint32 or masks with 0xFFFFFFFF without a range check.

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. Ariznawlll commented on Sep 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    Latest main (f72ca9efbeb3a7c673701e4a135cc6670c33cfde) confirms both parts of the conversion issue:

    1. Integer values outside [0, 4294967295] are masked to their low 32 bits instead of returning NULL.
    2. Fractional values are truncated, while MySQL rounds before applying the IPv4 range check.

    Examples repeated three times:

    input           MatrixOne         MySQL 8.3
    4294967296      0.0.0.0           NULL
    8589934591      255.255.255.255   NULL
    -1              255.255.255.255   NULL
    -4294967296     0.0.0.0           NULL
    0.5             0.0.0.0           0.0.0.1
    1.5             0.0.0.1           0.0.0.2
    4294967294.5    255.255.255.254   255.255.255.255
    4294967295.5    255.255.255.255   NULL
    

    Boundary controls 0, 1, 16909060, and 4294967295 agree with MySQL.

  6. Ariznawlll commented on Sep 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    在当前 main 6875e4203519de1ed98b842c1cbc8c57f11dc326 上,三轮双 CN、BIGINT 列、View、CTAS 和 server-side PreparedStatement 覆盖仍复现低 32 位截断。

    input        MatrixOne             MySQL 8.3 SELECT
    4294967296   0.0.0.0               NULL
    8589934591   255.255.255.255       NULL
    -1           255.255.255.255       NULL
    -2           255.255.255.254       NULL
    

    在列值 CTAS 路径中,MatrixOne 将这些截断后的地址写入结果表;MySQL 对相同列表达式报 ERROR 1411 Incorrect integer value,同样不会写入一个经截断的地址。0、4294967295、NULL 控制值一致。

  7. XuPeng-SH commented on Sep 12, 2026

    @XuPeng-SH
    Contributor

    PR #28800 fixes INET_NTOA numeric conversion by preserving input signedness/type and validating the converted value before narrowing, preventing negative and oversized values from wrapping into a valid address. It adds integer, DECIMAL, FLOAT/DOUBLE, vector, prepared, NULL, and boundary coverage. The PR is open; local UT/BVT were not run because the isolated worktree lacks provenance-validated CGo artifacts, and exact-head CI is still running.

  8. added a commit that references this issue on Sep 15, 2026
    f0f61f0
  9. Ariznawlll commented on Sep 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • MatrixOne main:0c3a04f390adaf6281fd592a49778ea5b1155e67
    • 本地 standalone(1 CN / 1 TN / 1 LogService),2026-09-15。

    原问题验证

    验证 INET_NTOA 对负数、超过 UINT32 的值返回 NULL,不再回绕为 IPv4 地址。

    Happy Path 覆盖

    覆盖 0、2130706433、4294967295 三个合法边界/常见 IPv4 整数。

    Unhappy Path 覆盖

    覆盖 -1、4294967296,确认均返回 NULL。

    白盒验证

    不适用:公开 SQL 输入边界已直接覆盖。

    回归测试

    已加入 MOTR:issue_28214_28217_ipv4_semantics,见 motr#176。

    测试证据

    新 MOTR 用例连续运行 3 轮成功,合法边界与越界拒绝均符合预期。

    测试结论

    测试通过。

  10. added 3 commits that reference this issue on Sep 17, 2026
    110e659
    0f3d83f
    5119681
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