Fix error handling in StyleAction::upload()
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 5 May 2016 20:03:38 +0000 (22:03 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Fri, 6 May 2016 12:01:50 +0000 (14:01 +0200)
wcfsetup/install/files/lib/data/style/StyleAction.class.php

index 8b1efb38d0384e52ab5bd244ae4b437370406bc4..1072cfa96a1d1725b763caecc9ebaf64cf34d256 100644 (file)
@@ -281,9 +281,22 @@ class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction
                        if (!$file->getValidationErrorType()) {
                                // shrink avatar if necessary
                                $fileLocation = $file->getLocation();
-                               $imageData = getimagesize($fileLocation);
-                               if ($imageData[0] > Style::PREVIEW_IMAGE_MAX_WIDTH || $imageData[1] > Style::PREVIEW_IMAGE_MAX_HEIGHT) {
-                                       try {
+                               try {
+                                       if (($imageData = getimagesize($fileLocation)) === false) {
+                                               throw new UserInputException('image');
+                                       }
+                                       switch ($imageData[2]) {
+                                               case IMG_PNG:
+                                               case IMG_JPEG:
+                                               case IMG_JPG:
+                                               case IMG_GIF:
+                                                       // fine
+                                               break;
+                                               default:
+                                                       throw new UserInputException('image');
+                                       }
+
+                                       if ($imageData[0] > Style::PREVIEW_IMAGE_MAX_WIDTH || $imageData[1] > Style::PREVIEW_IMAGE_MAX_HEIGHT) {
                                                $adapter = ImageHandler::getInstance()->getAdapter();
                                                $adapter->loadFile($fileLocation);
                                                $fileLocation = FileUtil::getTemporaryFilename();
@@ -291,9 +304,9 @@ class StyleAction extends AbstractDatabaseObjectAction implements IToggleAction
                                                $adapter->writeImage($thumbnail, $fileLocation);
                                                $imageData = getimagesize($fileLocation);
                                        }
-                                       catch (SystemException $e) {
-                                               throw new UserInputException('image');
-                                       }
+                               }
+                               catch (SystemException $e) {
+                                       throw new UserInputException('image');
                                }
                                
                                // move uploaded file