diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-04-23 23:28:14 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-04-23 23:28:14 +0200 |
commit | 9bfea215205597212fd2f367f3eedf217fb849f2 (patch) | |
tree | 61708451e784be072618e0c3eec952c750e22bea | |
parent | f5f5a07e38e6cb629fa62935f790760df06989fd (diff) | |
download | nextcloud-server-fix/32bit-support.tar.gz nextcloud-server-fix/32bit-support.zip |
fix(32bit): make `pack` compatible with 32bit PHPfix/32bit-support
The `P` formatter is 64bit only - we need to manually pack the 64bit.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r-- | lib/private/Security/Normalizer/IpAddress.php | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/private/Security/Normalizer/IpAddress.php b/lib/private/Security/Normalizer/IpAddress.php index e40dc9ba96b..b3793685a24 100644 --- a/lib/private/Security/Normalizer/IpAddress.php +++ b/lib/private/Security/Normalizer/IpAddress.php @@ -41,10 +41,14 @@ class IpAddress { $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; } |