Behaviour difference in ip2long() between AIX and Linux for IPs with leading zeros
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
We observed behaviour difference in ip2long() between AIX and LINUX when handling IPv4 addresses with leading zeros in one or more of their octets.
On AIX, IP address strings with leading zeros are accepted and processed successfully by ip2long().
On LINUX, same input is considered invalid and ip2long() returns FALSE.
The following code:
<?php
$tests = [
'192.168.42.42',
'192.168.042.42',
'010.000.000.001',
'127.0.0.1',
];
foreach ($tests as $ip) {
$val = ip2long($ip);
if ($val === false) {
echo "$ip => ip2long() returned FALSE\n";
} else {
echo "$ip => ip2long() = $val, normalized = " . long2ip($val) . "\n";
}
}
Resulted in this output:
192.168.42.42 => ip2long() = -1062720982, normalized = 192.168.42.42
192.168.042.42 => ip2long() = -1062720982, normalized = 192.168.42.42
010.000.000.001 => ip2long() = 167772161, normalized = 10.0.0.1
127.0.0.1 => ip2long() = 2130706433, normalized = 127.0.0.1
But I expected this output instead:
192.168.42.42 => ip2long() = -1062720982, normalized = 192.168.42.42
192.168.042.42 => ip2long() returned FALSE
010.000.000.001 => ip2long() returned FALSE
127.0.0.1 => ip2long() = 2130706433, normalized = 127.0.0.1
To maintain same behaviour as LINUX, we convert back the IP(ip) into a string and verify that it matches the original string. If not, the IP is considered invalid and returns FALSE. I will submit these changes via a PR. Please let me know your suggestions.
PHP Version
PHP 8.5.1 (cli) (built: Jan 20 2026 09:33:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.1, Copyright (c) Zend Technologies
with Zend OPcache v8.5.1, Copyright (c), by Zend Technologies
Operating System
AIX 7.2
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 AIX 和 Linux 上复现 ip2long() 示例,比较带前导零的 IPv4 八位字节的处理方式以及由此产生的 long2ip() 输出。跟踪 ip2long() 的实现及其依赖平台的解析过程,然后验证预期的无效输入会返回 FALSE,而其他示例仍保留其显示的结果。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- networking
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100