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] 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 c83cdb96e27..e88c307517d 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -264,8 +264,20 @@ class Generator { 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; }