From: Sascha Greuel Date: Wed, 9 Sep 2020 08:03:04 +0000 (+0200) Subject: Fix PHP 8 compatibility in GDImageAdapter (#3558) X-Git-Tag: 5.3.0_Beta_1~7^2~9 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=26f418a40e9f9d0d45bddff51f5778c4ec72c3a1;p=GitHub%2FWoltLab%2FWCF.git Fix PHP 8 compatibility in GDImageAdapter (#3558) Fixed image resource validation Resolves #3492 --- diff --git a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php index 6f8a873c19..ec600d89c5 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php @@ -56,11 +56,20 @@ class GDImageAdapter implements IImageAdapter { @ini_set('gd.jpeg_ignore_warning', '1'); } + /** + * Returns whether the given image is a valid GD resource / GD object + * + * @return boolean + */ + public function isImage($image) { + return (is_resource($image) && get_resource_type($image) === 'gd') || (is_object($image) && $image instanceof \GdImage); + } + /** * @inheritDoc */ public function load($image, $type = '') { - if (!is_resource($image)) { + if (!$this->isImage($image)) { throw new SystemException("Image resource is invalid."); } @@ -325,7 +334,7 @@ class GDImageAdapter implements IImageAdapter { * @inheritDoc */ public function writeImage($image, $filename) { - if (!is_resource($image)) { + if (!$this->isImage($image)) { throw new SystemException("Given image is not a valid image resource."); }