Suppress warnings for corrupt PNG, throw an exception instead
authorAlexander Ebert <ebert@woltlab.com>
Thu, 24 Aug 2017 14:59:53 +0000 (16:59 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 24 Aug 2017 14:59:53 +0000 (16:59 +0200)
wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php
wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php

index c8689c9e15913c755bfaecd9484ed790914d43bb..a768e0ce7404fd92d4f0f96ca6e374b37ff2dd53 100644 (file)
@@ -95,7 +95,11 @@ class GDImageAdapter implements IImageAdapter {
                        break;
                        
                        case IMAGETYPE_PNG:
-                               $this->image = imagecreatefrompng($file);
+                               // suppress warnings and properly handle errors
+                               $this->image = @imagecreatefrompng($file);
+                               if ($this->image === false) {
+                                       throw new SystemException("Could not read png image '".$file."'.");
+                               }
                        break;
                        
                        default:
index 8e320488168069159cf81547eb18e47e70522dc1..7ecb4c3da50984ba317af9127b0faef3d59746e9 100644 (file)
@@ -9,6 +9,7 @@ use wcf\data\user\UserEditor;
 use wcf\data\user\UserList;
 use wcf\data\user\UserProfileAction;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\SystemException;
 use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\image\ImageHandler;
 use wcf\system\user\activity\point\UserActivityPointHandler;
@@ -160,7 +161,16 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker {
                                        // make avatar quadratic
                                        $width = $height = min($width, $height, UserAvatar::AVATAR_SIZE);
                                        $adapter = ImageHandler::getInstance()->getAdapter();
-                                       $adapter->loadFile($avatar->getLocation());
+                                       
+                                       try {
+                                               $adapter->loadFile($avatar->getLocation());
+                                       }
+                                       catch (SystemException $e) {
+                                               // broken image
+                                               $editor->delete();
+                                               continue;
+                                       }
+                                       
                                        $thumbnail = $adapter->createThumbnail($width, $height, false);
                                        $adapter->writeImage($thumbnail, $avatar->getLocation());
                                }
@@ -168,7 +178,16 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker {
                                if ($width != UserAvatar::AVATAR_SIZE || $height != UserAvatar::AVATAR_SIZE) {
                                        // resize avatar
                                        $adapter = ImageHandler::getInstance()->getAdapter();
-                                       $adapter->loadFile($avatar->getLocation());
+                                       
+                                       try {
+                                               $adapter->loadFile($avatar->getLocation());
+                                       }
+                                       catch (SystemException $e) {
+                                               // broken image
+                                               $editor->delete();
+                                               continue;
+                                       }
+                                       
                                        $adapter->resize(0, 0, $width, $height, UserAvatar::AVATAR_SIZE, UserAvatar::AVATAR_SIZE);
                                        $adapter->writeImage($adapter->getImage(), $avatar->getLocation());
                                        $width = $height = UserAvatar::AVATAR_SIZE;