From 5d52de11b680078012eba04ae983058e6086b7d7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 28 Aug 2023 12:12:29 +0200 Subject: [PATCH] Revert "Remove check for `ini_parse_quantity`" see symfony/polyfill#442 This reverts commit 76b16ba4e89a7ff46cc2e1f79a158afc1c5e4c40. --- .../install/files/lib/util/FileUtil.class.php | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/util/FileUtil.class.php b/wcfsetup/install/files/lib/util/FileUtil.class.php index f54ffdce37..3cfba8d6a9 100644 --- a/wcfsetup/install/files/lib/util/FileUtil.class.php +++ b/wcfsetup/install/files/lib/util/FileUtil.class.php @@ -516,8 +516,30 @@ final class FileUtil // no limit if ($memoryLimit == "-1") { self::$memoryLimit = -1; - } else { + } else if (\function_exists('ini_parse_quantity')) { self::$memoryLimit = \ini_parse_quantity($memoryLimit); + } else { + // completely numeric, PHP assumes byte + if (\is_numeric($memoryLimit)) { + self::$memoryLimit = $memoryLimit; + } + + // PHP supports 'K', 'M' and 'G' shorthand notation + if (\preg_match('~^(\d+)\s*([KMG])$~i', $memoryLimit, $matches)) { + switch (\strtoupper($matches[2])) { + case 'K': + self::$memoryLimit = $matches[1] * 1024; + break; + + case 'M': + self::$memoryLimit = $matches[1] * 1024 * 1024; + break; + + case 'G': + self::$memoryLimit = $matches[1] * 1024 * 1024 * 1024; + break; + } + } } } -- 2.20.1