From 9819ed85807fb3804be4d9c559a8b16b3970435d Mon Sep 17 00:00:00 2001
From: Sascha Egerer <sascha@sascha-egerer.de>
Date: Wed, 25 Oct 2023 21:54:51 +0200
Subject: [PATCH] [BUGFIX] Make ContentRenderer catch more errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The ContentObjectRenderer catches \Exception's
that occur during the rendering of a content element.
However, since PHP 7, there is a \TypeError exception that
occurs, for example, if the given type does not match the
declared type.
Because \TypeError is not a subtype of \Exception, these
errors are not caught in the production context, and instead
of not rendering a single content element, the whole page
is not rendered.
Since all types of \Throwable are essentially errors that
will interrupt the rendering process, the catch block must
accommodate all of these, not just implementations of \Exception.

Resolves: #102044
Releases: main, 12.4, 11.5
Change-Id: If6218f013caf21d7fcd2c0d0d5b6b51c3bf9963e
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81573
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
---
 .../Classes/ContentObject/ContentObjectRenderer.php        | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
index 4492ef1f6fab..4559d5eb920a 100644
--- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
+++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
@@ -642,11 +642,16 @@ class ContentObjectRenderer implements LoggerAwareInterface
             // Content rendering Exceptions indicate a critical problem which should not be
             // caught e.g. when something went wrong with Exception handling itself
             throw $exception;
-        } catch (\Exception $exception) {
+        } catch (\Throwable $exception) {
             $exceptionHandler = $this->createExceptionHandler($configuration);
             if ($exceptionHandler === null) {
                 throw $exception;
             }
+            // Ensure that the exception handler receives an \Exception instance,
+            // which is required by the \ExceptionHandlerInterface.
+            if (!$exception instanceof \Exception) {
+                $exception = new \Exception($exception->getMessage(), 1698347363, $exception);
+            }
             $content = $exceptionHandler->handle($exception, $contentObject, $configuration);
         }
 
-- 
GitLab