Merge pull request #52402 from nextcloud/fix/32bit-pack

pull/52055/head
Kate 2025-04-28 21:23:17 +07:00 committed by GitHub
commit 10a01423ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

@ -42,8 +42,15 @@ class IpAddress {
$maskSize = min(64, $config->getSystemValueInt('security.ipv6_normalized_subnet_size', 56));
$maskSize = max(32, $maskSize);
if (PHP_INT_SIZE === 4) {
if ($maskSize === 64) {
$value = -1;
} elseif ($maskSize === 63) {
$value = PHP_INT_MAX;
} else {
$value = (1 << $maskSize - 32) - 1;
}
// as long as we support 32bit PHP we cannot use the `P` pack formatter (and not overflow 32bit integer)
$mask = pack('VVVV', 0xFFFF, $maskSize === 64 ? 0xFFFF : ((1 << $maskSize - 32) - 1), 0, 0);
$mask = pack('VVVV', -1, $value, 0, 0);
} else {
$mask = pack('VVP', (1 << 32) - 1, (1 << $maskSize - 32) - 1, 0);
}