From b5e7165487fd8aeebb3b914ae8b5336d2f22b07e Mon Sep 17 00:00:00 2001
From: Christian Weiske <weiske@mogic.com>
Date: Fri, 27 Oct 2023 11:13:50 +0200
Subject: [PATCH] [BUGFIX] Use original file for ProcessedFile::getMimeType and
 ::getSize

When the processed files are saved in a different storage,
calling `$this->getStorage()->getFileInfoByIdentifier()`
on a ProcessedFile that uses the original file will fail.

This patch proxies the calls to the original file if necessary,
just as it is already done for e.g. exists() and getPublicUrl().

Resolves: #102267
Releases: main, 12.4
Change-Id: I862340e377eef306c906bf35bf171a82876fdc01
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81593
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Guido Schmechel <guido.schmechel@brandung.de>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Garvin Hicking <gh@faktor-e.de>
Tested-by: Garvin Hicking <gh@faktor-e.de>
---
 .../core/Classes/Resource/ProcessedFile.php   | 26 +++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/typo3/sysext/core/Classes/Resource/ProcessedFile.php b/typo3/sysext/core/Classes/Resource/ProcessedFile.php
index 3edbee4f7f0c..5d643650da1f 100644
--- a/typo3/sysext/core/Classes/Resource/ProcessedFile.php
+++ b/typo3/sysext/core/Classes/Resource/ProcessedFile.php
@@ -435,6 +435,32 @@ class ProcessedFile extends AbstractFile
         return $this->properties[$key] ?? null;
     }
 
+    /**
+     * Get the MIME type of this file
+     *
+     * @throws \RuntimeException
+     * @return non-empty-string mime type
+     */
+    public function getMimeType(): string
+    {
+        if ($this->usesOriginalFile()) {
+            return $this->getOriginalFile()->getMimeType();
+        }
+        return parent::getMimeType();
+    }
+
+    /**
+     * @throws \RuntimeException
+     * @return int<0, max>
+     */
+    public function getSize(): int
+    {
+        if ($this->usesOriginalFile()) {
+            return $this->getOriginalFile()->getSize();
+        }
+        return parent::getSize();
+    }
+
     /**
      * Returns the uid of this file
      */
-- 
GitLab