From f6953bda186c1cb10d01b37a1e3071148b87b16c Mon Sep 17 00:00:00 2001
From: Sascha Egerer <sascha@sascha-egerer.de>
Date: Fri, 3 Nov 2017 20:48:56 +0100
Subject: [PATCH] [TASK] Do not silently ignore exceptions in ImageViewhelper

Exceptions in the ImageViewhelper are currently silently ignored.
So you'll get no information if a wrong value has been passed
to the src attribute or if there went something wrong.
The exception is not rethrown as Fluid viewhelper exception so
it will be catched and logged in Production Context by the
AbstractViewhelper that calls the render method.

Change-Id: I95124ebb945366d260b4351ccb85d61a399c50b5
Resolves: #82918
Releases: master
Reviewed-on: https://review.typo3.org/54561
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Manuel Selbach <manuel_selbach@yahoo.de>
Reviewed-by: Jan Stockfisch <jan.stockfisch@googlemail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
---
 .../sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php | 9 +++++++--
 .../fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php    | 6 +++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
index 375a61c184af..7b20e4b0389b 100644
--- a/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
+++ b/typo3/sysext/fluid/Classes/ViewHelpers/ImageViewHelper.php
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Fluid\ViewHelpers;
 
 use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
 use TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
 
 /**
  * Resizes a given image (if required) and renders the respective img tag
@@ -113,13 +114,13 @@ class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
      *
      * @see https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Image/
      *
-     * @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
+     * @throws Exception
      * @return string Rendered tag
      */
     public function render()
     {
         if ((is_null($this->arguments['src']) && is_null($this->arguments['image'])) || (!is_null($this->arguments['src']) && !is_null($this->arguments['image']))) {
-            throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('You must either specify a string src or a File object.', 1382284106);
+            throw new Exception('You must either specify a string src or a File object.', 1382284106);
         }
 
         try {
@@ -165,12 +166,16 @@ class ImageViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedV
             }
         } catch (ResourceDoesNotExistException $e) {
             // thrown if file does not exist
+            throw new Exception($e->getMessage(), 1509741911, $e);
         } catch (\UnexpectedValueException $e) {
             // thrown if a file has been replaced with a folder
+            throw new Exception($e->getMessage(), 1509741912, $e);
         } catch (\RuntimeException $e) {
             // RuntimeException thrown if a file is outside of a storage
+            throw new Exception($e->getMessage(), 1509741913, $e);
         } catch (\InvalidArgumentException $e) {
             // thrown if file storage does not exist
+            throw new Exception($e->getMessage(), 1509741914, $e);
         }
 
         return $this->tag->render();
diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
index a95766de4d54..c7e62f5780ea 100644
--- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
+++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/ImageViewHelper.php
@@ -20,8 +20,8 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Extbase\Service\ImageService;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
-use TYPO3\CMS\Fluid\Core\ViewHelper\Exception;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
+use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
 
 /**
@@ -133,12 +133,16 @@ class ImageViewHelper extends AbstractViewHelper
             return $imageService->getImageUri($processedImage, $absolute);
         } catch (ResourceDoesNotExistException $e) {
             // thrown if file does not exist
+            throw new Exception($e->getMessage(), 1509741907, $e);
         } catch (\UnexpectedValueException $e) {
             // thrown if a file has been replaced with a folder
+            throw new Exception($e->getMessage(), 1509741908, $e);
         } catch (\RuntimeException $e) {
             // RuntimeException thrown if a file is outside of a storage
+            throw new Exception($e->getMessage(), 1509741909, $e);
         } catch (\InvalidArgumentException $e) {
             // thrown if file storage does not exist
+            throw new Exception($e->getMessage(), 1509741910, $e);
         }
         return '';
     }
-- 
GitLab