From 4b97e1614bf3574e0252795da7d87e0759948cc9 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Thu, 27 Apr 2023 16:38:32 +0200 Subject: [PATCH 1/2] Check for open_basedir before reading /proc Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/private/Preview/Generator.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index c83cdb96e2719..e88c307517de4 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -264,8 +264,20 @@ public static function unguardWithSemaphore(false|\SysvSemaphore $semId): bool { public static function getHardwareConcurrency(): int { static $width; if (!isset($width)) { - if (is_file("/proc/cpuinfo")) { - $width = substr_count(file_get_contents("/proc/cpuinfo"), "processor"); + if (function_exists('ini_get')) { + $openBasedir = ini_get('open_basedir'); + if ($openBasedir == '') { + $width = is_readable('/proc/cpuinfo') ? substr_count(file_get_contents('/proc/cpuinfo'), 'processor') : 0; + } else { + $openBasedirPaths = explode(':', $openBasedir); + foreach ($openBasedirPaths as $path) { + if (strpos($path, '/proc') === 0 || $path === '/proc/cpuinfo') { + $width = is_readable('/proc/cpuinfo') ? substr_count(file_get_contents('/proc/cpuinfo'), 'processor') : 0; + } else { + $width = 0; + } + } + } } else { $width = 0; } From febc24db137f585de2b6871ac64e474b07142f65 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Thu, 27 Apr 2023 19:26:59 +0200 Subject: [PATCH 2/2] Us strpos() only Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> --- lib/private/Preview/Generator.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index e88c307517de4..f1a43ee9128a6 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -263,20 +263,14 @@ public static function unguardWithSemaphore(false|\SysvSemaphore $semId): bool { */ public static function getHardwareConcurrency(): int { static $width; + if (!isset($width)) { if (function_exists('ini_get')) { $openBasedir = ini_get('open_basedir'); - if ($openBasedir == '') { + if (empty($openBasedir) || strpos($openBasedir, '/proc/cpuinfo') !== false) { $width = is_readable('/proc/cpuinfo') ? substr_count(file_get_contents('/proc/cpuinfo'), 'processor') : 0; } else { - $openBasedirPaths = explode(':', $openBasedir); - foreach ($openBasedirPaths as $path) { - if (strpos($path, '/proc') === 0 || $path === '/proc/cpuinfo') { - $width = is_readable('/proc/cpuinfo') ? substr_count(file_get_contents('/proc/cpuinfo'), 'processor') : 0; - } else { - $width = 0; - } - } + $width = 0; } } else { $width = 0;