Fix PHP 8 compatibility in GDImageAdapter (#3558)
authorSascha Greuel <sascha@softcreatr.de>
Wed, 9 Sep 2020 08:03:04 +0000 (10:03 +0200)
committerGitHub <noreply@github.com>
Wed, 9 Sep 2020 08:03:04 +0000 (10:03 +0200)
Fixed image resource validation

Resolves #3492

wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php

index 6f8a873c19f568a681c998699d56d17eeb739689..ec600d89c50beb8f7f288cc69e335bef94b051b1 100644 (file)
@@ -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.");
                }