From fa59ded86fe169ee07fb212dd6e8a864cad5c9f4 Mon Sep 17 00:00:00 2001 From: Lukas Gaechter Date: Mon, 19 Aug 2024 13:53:57 +0200 Subject: [PATCH] fix: Prevent using simplexml_load_file() on missing file --- lib/Helper.php | 4 ++++ lib/Image.php | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Helper.php b/lib/Helper.php index 6f74a12..0d46e5e 100644 --- a/lib/Helper.php +++ b/lib/Helper.php @@ -496,6 +496,10 @@ public static function get_mime_types() { * @return array|null */ public static function get_svg_dimensions( $svg ) { + if ( ! file_exists( $svg ) ) { + return null; + } + $svg = simplexml_load_file( $svg ); $width = 0; $height = 0; diff --git a/lib/Image.php b/lib/Image.php index 6456186..04c3c08 100644 --- a/lib/Image.php +++ b/lib/Image.php @@ -76,7 +76,7 @@ class Image { * * @var array */ - protected $svg_dimensions = []; + protected array $svg_dimensions = []; final protected function __construct() { } @@ -991,7 +991,7 @@ public function description() { */ public function svg_dimensions() { if ( empty( $this->svg_dimensions ) ) { - $this->svg_dimensions = Helper::get_svg_dimensions( $this->path() ); + $this->svg_dimensions = Helper::get_svg_dimensions( $this->path() ) ?: []; } return $this->svg_dimensions;