From ecfd80be34be8f49a5fc770974e4b807b5bac9bf Mon Sep 17 00:00:00 2001
From: Thomas Hohn <thomas@hohn.dk>
Date: Tue, 28 Feb 2023 10:02:10 +0100
Subject: [PATCH] [BUGFIX] Handle getFileContents in LocalDriver better

The method getFileContents has return value string. But since
there is no guarantee that the file exists before calling
file_get_contents, a call to is_readable has been added.
This handles both the PHP Warning and ensures type correctness.

Resolves: #99926
Releases: main, 11.5
Change-Id: I9786a6737d7e3b0c3d04272364d868fd4101307c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77978
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
Reviewed-by: JAKOTA Design Group GmbH <suchowski@jakota.de>
---
 typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php b/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
index ce533019f89a..d0cce1f1840e 100644
--- a/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
+++ b/typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
@@ -1346,12 +1346,12 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver implements Stream
      * processing resources and money) for large files.
      *
      * @param string $fileIdentifier
-     * @return string The file contents
+     * @return string The file contents if file exists and else empty string
      */
     public function getFileContents($fileIdentifier)
     {
         $filePath = $this->getAbsolutePath($fileIdentifier);
-        return file_get_contents($filePath);
+        return is_readable($filePath) ? (string)file_get_contents($filePath) : '';
     }
 
     /**
-- 
GitLab