Skip to content

Commit 9bfea21

Browse files
committed
fix(32bit): make pack compatible with 32bit PHP
The `P` formatter is 64bit only - we need to manually pack the 64bit. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent f5f5a07 commit 9bfea21

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/private/Security/Normalizer/IpAddress.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ private function getIPv6Subnet(string $ip): string {
4141
$config = \OCP\Server::get(IConfig::class);
4242
$maskSize = min(64, $config->getSystemValueInt('security.ipv6_normalized_subnet_size', 56));
4343
$maskSize = max(32, $maskSize);
44-
$mask = pack('VVP', (1 << 32) - 1, (1 << $maskSize - 32) - 1, 0);
44+
if (PHP_INT_SIZE === 4) {
45+
// as long as we support 32bit PHP we cannot use the `P` pack formatter (and not overflow 32bit integer)
46+
$mask = pack('VVVV', 0xFFFF, $maskSize === 64 ? 0xFFFF : ((1 << $maskSize - 32) - 1), 0, 0);
47+
} else {
48+
$mask = pack('VVP', (1 << 32) - 1, (1 << $maskSize - 32) - 1, 0);
49+
}
4550

4651
$binary = \inet_pton($ip);
47-
4852
return inet_ntop($binary & $mask) . '/' . $maskSize;
4953
}
5054

0 commit comments

Comments
 (0)