From 63190ba3dce3c296d734f97be52310cfae310cba Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 5 Sep 2016 20:59:15 +0200 Subject: [PATCH] Do not rely on mime type for image validation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … for those systems without `\finfo`. --- .../MediaUploadFileValidationStrategy.class.php | 2 +- .../files/lib/system/upload/UploadFile.class.php | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/wcfsetup/install/files/lib/system/upload/MediaUploadFileValidationStrategy.class.php b/wcfsetup/install/files/lib/system/upload/MediaUploadFileValidationStrategy.class.php index 2096fff0cc..f8fceac8d3 100644 --- a/wcfsetup/install/files/lib/system/upload/MediaUploadFileValidationStrategy.class.php +++ b/wcfsetup/install/files/lib/system/upload/MediaUploadFileValidationStrategy.class.php @@ -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; } diff --git a/wcfsetup/install/files/lib/system/upload/UploadFile.class.php b/wcfsetup/install/files/lib/system/upload/UploadFile.class.php index 55ace04329..689bdb7d6b 100644 --- a/wcfsetup/install/files/lib/system/upload/UploadFile.class.php +++ b/wcfsetup/install/files/lib/system/upload/UploadFile.class.php @@ -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; -- 2.20.1