Behaviour difference in ip2long() between AIX and Linux for IPs with leading zeros
まだ誰も着手していません。
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.1k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず AIX と Linux で ip2long() の例を再現し、先頭にゼロが付いた IPv4 オクテットの扱いと、それによって得られる long2ip() の出力を比較します。次に、ip2long() の実装とプラットフォーム依存の解析処理を追跡し、想定される無効な入力が FALSE を返すことを確認するとともに、その他の例では示されている結果が維持されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- php
- 領域
- networking
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100