Fixed XF\Util\Ip::convertIpBinaryToString produces invalid IPv6 address

Steffen

Well-known member
Affected version
2.0.2
PHP:
<?php
$dir = __DIR__;
require ($dir . '/src/XF.php');
XF::start($dir);

$ip = '1000:2000:3000:4000::';
$binaryIp = \XF\Util\Ip::convertIpStringToBinary($ip);
$ip2 = \XF\Util\Ip::convertIpBinaryToString($binaryIp);

var_dump($ip, $ip2);

Code:
$ php ip-bug.php
string(21) "1000:2000:3000:4000::"
string(20) "1000:2000:3000:4000:"
 
PHP:
<?php
$ip = '1000:2000:3000:4000::';
$binaryIp = inet_pton($ip);
$ip2 = inet_ntop($binaryIp);

var_dump($ip, $ip2);

Code:
$ php ip-bug2.php
string(21) "1000:2000:3000:4000::"
string(21) "1000:2000:3000:4000::"
 
This should be fixed now. (We can potentially use inet_ntop for this in some scenarios so we may consider that in the future, though we do possibly still need the fallback.)
 
Back
Top Bottom