Skip to content

Commit

Permalink
fix: Prevent using simplexml_load_file() on missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Aug 19, 2024
1 parent 59b1f82 commit fa59ded
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Image {
*
* @var array
*/
protected $svg_dimensions = [];
protected array $svg_dimensions = [];

final protected function __construct() {
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fa59ded

Please sign in to comment.