From b38ab1b87d28b79379acfd5bc5e60a942513185f Mon Sep 17 00:00:00 2001 From: Frank Maesen Date: Sun, 27 Nov 2022 14:55:12 +0100 Subject: [PATCH 1/2] Fix PHP warning : is_readable() - open_basedir restriction in effect. --- core/components/phpthumbof/model/phpthumbof.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/components/phpthumbof/model/phpthumbof.class.php b/core/components/phpthumbof/model/phpthumbof.class.php index 4e1141d..d564666 100644 --- a/core/components/phpthumbof/model/phpthumbof.class.php +++ b/core/components/phpthumbof/model/phpthumbof.class.php @@ -257,7 +257,7 @@ public function createThumbnail($src, $options) { } } else { // it's a local file - if (is_readable($src)) { // if we've already got an existing file, keep going + if (!is_string(ini_get('open_basedir')) && is_readable($src)) { // if we've already got an existing file, keep going $file = $src; } else { // otherwise prepend base_path and try again From e7704034beaf4d7d52f6d60e89151af6001c4a0f Mon Sep 17 00:00:00 2001 From: Frank Maesen Date: Mon, 28 Nov 2022 17:54:20 +0100 Subject: [PATCH 2/2] More general fix for PHP warning open_basedir restriction in effect. --- .../phpthumbof/model/phpthumbof.class.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/components/phpthumbof/model/phpthumbof.class.php b/core/components/phpthumbof/model/phpthumbof.class.php index d564666..e6fcfc0 100644 --- a/core/components/phpthumbof/model/phpthumbof.class.php +++ b/core/components/phpthumbof/model/phpthumbof.class.php @@ -257,7 +257,20 @@ public function createThumbnail($src, $options) { } } else { // it's a local file - if (!is_string(ini_get('open_basedir')) && is_readable($src)) { // if we've already got an existing file, keep going + // see if open_basedir is active - avoid calling is_readable in PHP >= 8.x + $openBasedirIniSetting = ini_get('open_basedir'); + $isOpenBasedirSafe = true; + if (is_string($openBasedirIniSetting)) { + $isOpenBasedirSafe = false; + $openBasedirPaths = explode(":", $openBasedirIniSetting); + foreach($openBasedirPaths as $path) { + if (substr($src, 0, strlen($path)) == $path) { + $isOpenBasedirSafe = true; + break; + } + } + } + if ($isOpenBasedirSafe && is_readable($src)) { // if we've already got an existing file, keep going $file = $src; } else { // otherwise prepend base_path and try again