From 30c5f2451eb0d5a018c580e8e7f9519d7d9ee6b3 Mon Sep 17 00:00:00 2001 From: Josh Richards Date: Thu, 27 Apr 2023 13:21:11 -0400 Subject: [PATCH] Fix open_basedir preview interaction + simple OS fallback Signed-off-by: Josh Richards --- lib/private/Preview/Generator.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index ed9474fafb217..1400f4e09a7cb 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -295,10 +295,16 @@ public static function unguardWithSemaphore($semId): bool { */ public static function getHardwareConcurrency(): int { static $width; + // NOTE: This is a no-op anyhow if the admin sets preview_concurrency_* parameters which will override anything based on the below findings if (!isset($width)) { - if (is_file("/proc/cpuinfo")) { + if (!ini_get('open_basedir') && is_readable("/proc/cpuinfo")) { + // No restrictions and available $width = substr_count(file_get_contents("/proc/cpuinfo"), "processor"); } else { + // Unable to determine CPU count from OS (will use defaults or configured values) + // Too complicated/taxing to check if entire open_basedir is okay + // Plus issue might be a different OS so punt to defaults + // (possibly overrriden by config anyhow) $width = 0; } } @@ -326,6 +332,8 @@ public function getNumConcurrentPreviews(string $type): int { return $cached[$type]; } + // TODO: Check for configured values and use them before bothering with "guessing" + $hardwareConcurrency = self::getHardwareConcurrency(); switch ($type) { case "preview_concurrency_all":