diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Http.php b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Http.php index 4d7bbc3c9..53c0388db 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Base/Http.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Base/Http.php @@ -253,7 +253,8 @@ class Http 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', - 416 => 'Requested range not satisfiable' + 416 => 'Requested range not satisfiable', + 500 => 'Internal Server Error' ); $sHeaderText = (0 === \strlen($sCustomStatusText) && isset($aStatus[$iStatus]) ? $aStatus[$iStatus] : $sCustomStatusText); diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Raw.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Raw.php index 8770e7eb8..8f135d474 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Raw.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Raw.php @@ -207,37 +207,32 @@ trait Raw if (!$bDownload) { $bDetectImageOrientation = !!$self->Config()->Get('labs', 'detect_image_exif_orientation', false); - if ($bThumbnail) + try { - try + if ($bThumbnail) { $oImage = static::loadImage($rResource, $bDetectImageOrientation, 60); \header('Content-Disposition: inline; '. \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileName.'_thumb60x60.png'))); $oImage->show('png'); // $oImage->show('webp'); // Little Britain: "Safari says NO" + exit; } - catch (\Throwable $oException) - { - $self->Logger()->WriteExceptionShort($oException); - } - exit; - } - else if ($bDetectImageOrientation && - \in_array($sContentType, array('image/png', 'image/jpeg', 'image/jpg', 'image/webp'))) - { - try + else if ($bDetectImageOrientation && + \in_array($sContentType, array('image/png', 'image/jpeg', 'image/jpg', 'image/webp'))) { $oImage = static::loadImage($rResource, $bDetectImageOrientation); \header('Content-Disposition: inline; '. \trim(\MailSo\Base\Utils::EncodeHeaderUtf8AttributeValue('filename', $sFileName))); $oImage->show(); // $oImage->show('webp'); // Little Britain: "Safari says NO" + exit; } - catch (\Throwable $oException) - { - $self->Logger()->WriteExceptionShort($oException); - } + } + catch (\Throwable $oException) + { + $self->Logger()->WriteExceptionShort($oException); + \MailSo\Base\Http::StatusHeader(500); exit; } } @@ -306,6 +301,10 @@ trait Raw $handler = 'SnappyMail\\Image\\'.$handler.'::createFromStream'; $oImage = $handler($resource); + if (!$oImage->valid()) { + throw new \Exception('Loading image failed'); + } + // rotateImageByOrientation if ($bDetectImageOrientation) { switch ($oImage->getOrientation()) diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/image.php b/snappymail/v/0.0.0/app/libraries/snappymail/image.php index b9991964d..935b79cbc 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/image.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/image.php @@ -13,4 +13,6 @@ interface Image public function rotate(float $degrees) : bool; public function show(?string $format = null) : void; + + public function valid() : bool; } diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/image/gd2.php b/snappymail/v/0.0.0/app/libraries/snappymail/image/gd2.php index 59a955d34..b4dd61aab 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/image/gd2.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/image/gd2.php @@ -29,6 +29,11 @@ class GD2 implements \SnappyMail\Image return $this->getImageBlob(); } + public function valid() : bool + { + return $this->img && 0 < \imagesx($this->img); + } + public static function createFromString(string &$data) { if (!($imginfo = \getimagesizefromstring($data))) { diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/image/gmagick.php b/snappymail/v/0.0.0/app/libraries/snappymail/image/gmagick.php index eea717475..db07747db 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/image/gmagick.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/image/gmagick.php @@ -14,6 +14,11 @@ class GMagick extends \Gmagick implements \SnappyMail\Image $this->clear(); } + public function valid() : bool + { + return 0 < $this->getImageWidth(); + } + public static function createFromString(string &$data) { $gmagick = new static(); diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/image/imagick.php b/snappymail/v/0.0.0/app/libraries/snappymail/image/imagick.php index 743e215cd..ff9c7807d 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/image/imagick.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/image/imagick.php @@ -11,6 +11,11 @@ class IMagick extends \Imagick implements \SnappyMail\Image $this->clear(); } + public function valid() : bool + { + return 0 < $this->getImageWidth(); + } + public static function createFromString(string &$data) { $imagick = new static();