diff options
author | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2025-04-24 09:53:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-24 09:53:20 +0200 |
commit | 7a50f612d762c0c48c7a362f14a46a645ec60596 (patch) | |
tree | d3b090a582f5a194c4012d40d8e7c58d38d94dce | |
parent | d86189adc5bfd0af526db4f8851d935ac97c4a76 (diff) | |
parent | 9bfea215205597212fd2f367f3eedf217fb849f2 (diff) | |
download | nextcloud-server-7a50f612d762c0c48c7a362f14a46a645ec60596.tar.gz nextcloud-server-7a50f612d762c0c48c7a362f14a46a645ec60596.zip |
Merge pull request #52392 from nextcloud/fix/32bit-support
fix(32bit): make `pack` compatible with 32bit PHP
-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; } |