Skip to content

Commit 10a0142

Browse files
Merge pull request #52402 from nextcloud/fix/32bit-pack
2 parents 40e52e2 + a221715 commit 10a0142

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/private/Security/Normalizer/IpAddress.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ private function getIPv6Subnet(string $ip): string {
4242
$maskSize = min(64, $config->getSystemValueInt('security.ipv6_normalized_subnet_size', 56));
4343
$maskSize = max(32, $maskSize);
4444
if (PHP_INT_SIZE === 4) {
45+
if ($maskSize === 64) {
46+
$value = -1;
47+
} elseif ($maskSize === 63) {
48+
$value = PHP_INT_MAX;
49+
} else {
50+
$value = (1 << $maskSize - 32) - 1;
51+
}
4552
// 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);
53+
$mask = pack('VVVV', -1, $value, 0, 0);
4754
} else {
4855
$mask = pack('VVP', (1 << 32) - 1, (1 << $maskSize - 32) - 1, 0);
4956
}

0 commit comments

Comments
 (0)