Do not rely on mime type for image validation
authorMatthias Schmidt <gravatronics@live.com>
Mon, 5 Sep 2016 18:59:15 +0000 (20:59 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Mon, 5 Sep 2016 18:59:15 +0000 (20:59 +0200)
… for those systems without `\finfo`.

wcfsetup/install/files/lib/system/upload/MediaUploadFileValidationStrategy.class.php
wcfsetup/install/files/lib/system/upload/UploadFile.class.php

index 2096fff0ccb7539ab2a0627cd684fa81b739e844..f8fceac8d3a38ceb53e57ec9f334a7747c30db00 100644 (file)
@@ -35,7 +35,7 @@ class MediaUploadFileValidationStrategy implements IUploadFileValidationStrategy
                        return false;
                }
                
-               if (!empty($this->fileTypeFilters['isImage']) && ($uploadFile->getImageData() === null || !preg_match('~^image/(gif|jpe?g|png)$~i', $uploadFile->getMimeType()))) {
+               if (!empty($this->fileTypeFilters['isImage']) && $uploadFile->getImageData() === null) {
                        $uploadFile->setValidationErrorType('noImage');
                        return false;
                }
index 55ace04329e833dea168d48a737f88a083c47dac..689bdb7d6b4ccd06c44adfd996ef821e70d052e6 100644 (file)
@@ -165,14 +165,12 @@ class UploadFile {
         * @return      array|null
         */
        public function getImageData() {
-               if (strpos($this->getMimeType(), 'image/') == 0) {
-                       if (($imageData = @getimagesize($this->getLocation())) !== false) {
-                               return [
-                                       'width' => $imageData[0],
-                                       'height' => $imageData[1],
-                                       'mimeType' => $imageData['mime']
-                               ];
-                       }
+               if (($imageData = @getimagesize($this->getLocation())) !== false) {
+                       return [
+                               'width' => $imageData[0],
+                               'height' => $imageData[1],
+                               'mimeType' => $imageData['mime']
+                       ];
                }
                
                return null;