Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
susnux committed Apr 23, 2025
commit 9bfea215205597212fd2f367f3eedf217fb849f2
8 changes: 6 additions & 2 deletions lib/private/Security/Normalizer/IpAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ private function getIPv6Subnet(string $ip): string {
$config = \OCP\Server::get(IConfig::class);
$maskSize = min(64, $config->getSystemValueInt('security.ipv6_normalized_subnet_size', 56));
$maskSize = max(32, $maskSize);
$mask = pack('VVP', (1 << 32) - 1, (1 << $maskSize - 32) - 1, 0);
if (PHP_INT_SIZE === 4) {
// 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);
} else {
$mask = pack('VVP', (1 << 32) - 1, (1 << $maskSize - 32) - 1, 0);
}

$binary = \inet_pton($ip);

return inet_ntop($binary & $mask) . '/' . $maskSize;
}

Expand Down
Loading