From 2aec132b49e4fd3905249cf25fa62f9c48624e2a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 30 Jul 2024 14:42:28 +0200 Subject: [PATCH] wip #7026 @0:10 --- src/Graphics/Image.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Graphics/Image.php b/src/Graphics/Image.php index 3f326c2..f514ae7 100644 --- a/src/Graphics/Image.php +++ b/src/Graphics/Image.php @@ -12,6 +12,13 @@ use Illuminate\Support\Facades\Log; class Image { protected static $_imagesizeCache = []; + protected static $_extensions = ['svg', 'oam', 'zip', 'jpeg', 'jpg', 'gif', 'png', 'webm', 'pdf', 'html']; + + public static function isValidImage($path) + { + + return in_array(Files::getExtension($path), self::$_extensions); + } /** * @throws \Exception @@ -21,14 +28,12 @@ class Image if (!file_exists($path)) { throw new \Exception('File ' . $path . ' does not exist'); } - - $allowedExtensions = ['svg', 'oam', 'zip', 'jpeg', 'jpg', 'gif', 'png', 'webm', 'pdf', 'html']; - - $ext = Files::getExtension($path); - if (!in_array($ext, $allowedExtensions)) { + if (!self::isValidImage($path)) { throw new \Exception('File ' . $path . ' is not a valid image'); } + $ext = Files::getExtension($path); + $cacheKey = 'getimagesize_' . Files::hashFileAttributes($path); if (isset(self::$_imagesizeCache[$cacheKey])) { return self::$_imagesizeCache[$cacheKey]; -- 2.39.5