From cdd1e00644b8735011701772ed1467b71adbc621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Passault?= Date: Mon, 23 Sep 2024 16:45:30 +0200 Subject: [PATCH] Ignoring phar archives (see #193) --- Adapter/GD.php | 9 +++++---- Source/File.php | 3 ++- Utils/FileUtils.php | 22 ++++++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 Utils/FileUtils.php diff --git a/Adapter/GD.php b/Adapter/GD.php index 34c301c..c0a1f15 100644 --- a/Adapter/GD.php +++ b/Adapter/GD.php @@ -4,6 +4,7 @@ use Gregwar\Image\Image; use Gregwar\Image\ImageColor; +use Gregwar\Image\Utils\FileUtils; class GD extends Common { @@ -609,7 +610,7 @@ public function saveJpeg($file, $quality) */ protected function openJpeg($file) { - if (file_exists($file) && filesize($file)) { + if (FileUtils::safeExists($file) && filesize($file)) { $this->resource = @imagecreatefromjpeg($file); } else { $this->resource = false; @@ -621,7 +622,7 @@ protected function openJpeg($file) */ protected function openGif($file) { - if (file_exists($file) && filesize($file)) { + if (FileUtils::safeExists($file) && filesize($file)) { $this->resource = @imagecreatefromgif($file); } else { $this->resource = false; @@ -633,7 +634,7 @@ protected function openGif($file) */ protected function openPng($file) { - if (file_exists($file) && filesize($file)) { + if (FileUtils::safeExists($file) && filesize($file)) { $this->resource = @imagecreatefrompng($file); } else { $this->resource = false; @@ -645,7 +646,7 @@ protected function openPng($file) */ protected function openWebp($file) { - if (file_exists($file) && filesize($file)) { + if (FileUtils::safeExists($file) && filesize($file)) { $this->resource = @imagecreatefromwebp($file); } else { $this->resource = false; diff --git a/Source/File.php b/Source/File.php index ceed26b..d580891 100644 --- a/Source/File.php +++ b/Source/File.php @@ -3,6 +3,7 @@ namespace Gregwar\Image\Source; use Gregwar\Image\Image; +use Gregwar\Image\Utils\FileUtils; /** * Open an image from a file. @@ -28,7 +29,7 @@ public function correct() public function guessType() { - if (function_exists('exif_imagetype')) { + if (function_exists('exif_imagetype') && FileUtils::safeExists($this->file)) { $type = @exif_imagetype($this->file); if (false !== $type) { diff --git a/Utils/FileUtils.php b/Utils/FileUtils.php new file mode 100644 index 0000000..376a425 --- /dev/null +++ b/Utils/FileUtils.php @@ -0,0 +1,22 @@ +