From c5c9e424243c4c5775e73a616dbf6d605a5f50d8 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 24 Aug 2017 16:59:53 +0200 Subject: [PATCH] Suppress warnings for corrupt PNG, throw an exception instead --- .../image/adapter/GDImageAdapter.class.php | 6 ++++- .../worker/UserRebuildDataWorker.class.php | 23 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) 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 c8689c9e15..a768e0ce74 100644 --- a/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php +++ b/wcfsetup/install/files/lib/system/image/adapter/GDImageAdapter.class.php @@ -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: diff --git a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php index 8e32048816..7ecb4c3da5 100644 --- a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php @@ -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; -- 2.20.1