Skip to content

Commit 225b080

Browse files
committed
[BUGFIX] Handle invalid source string correctly in ImageService
The ImageService->getImageFromSourceString() tries to retrieve a FileInterface from a given source string, e.g. with the "EXT:" prefix. However, because the used ResourceFactory->retrieveFileOrFolderObject() method can also return a FolderInterface or NULL, this must be handled to prevent a TypeError. Therefore, the final $image value is now checked for being a FileInterface. Otherwise NULL is returned, which is then handled with a custom exception in the calling `getImage()` method. Resolves: #94495 Releases: master, 10.4 Change-Id: I95836fd3c1701cc8c9b9e07c5b8e10a7fb9ee9cc Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69729 Tested-by: core-ci <typo3@b13.com> Tested-by: Jochen <rothjochen@gmail.com> Tested-by: Benni Mack <benni@typo3.org> Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Geert Boetzkes <geert.boetzkes@beech.it> Reviewed-by: Jochen <rothjochen@gmail.com> Reviewed-by: Benni Mack <benni@typo3.org> Reviewed-by: Oliver Bartsch <bo@cedev.de>
1 parent cf55f1d commit 225b080

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

typo3/sysext/extbase/Classes/Service/ImageService.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ public function getImage(string $src, $image, bool $treatIdAsReference): FileInt
136136
$image = $image->getOriginalResource();
137137
}
138138

139+
if ($image === null) {
140+
throw new \UnexpectedValueException('Supplied file is NULL, but must be File or FileReference.', 1625585157);
141+
}
139142
if (!($image instanceof File || $image instanceof FileReference)) {
140143
throw new \UnexpectedValueException('Supplied file object type ' . get_class($image) . ' for ' . $src . ' must be File or FileReference.', 1382687163);
141144
}
@@ -148,9 +151,9 @@ public function getImage(string $src, $image, bool $treatIdAsReference): FileInt
148151
*
149152
* @param string $src
150153
* @param bool $treatIdAsReference
151-
* @return FileInterface|FileReference|\TYPO3\CMS\Core\Resource\Folder
154+
* @return FileInterface|null
152155
*/
153-
protected function getImageFromSourceString(string $src, bool $treatIdAsReference): object
156+
protected function getImageFromSourceString(string $src, bool $treatIdAsReference): ?FileInterface
154157
{
155158
if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
156159
&& ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
@@ -173,7 +176,9 @@ protected function getImageFromSourceString(string $src, bool $treatIdAsReferenc
173176
// We have a combined identifier or legacy (storage 0) path
174177
$image = $this->resourceFactory->retrieveFileOrFolderObject($src);
175178
}
176-
return $image;
179+
180+
// Check the resolved image as this could also be a FolderInterface
181+
return $image instanceof FileInterface ? $image : null;
177182
}
178183

179184
/**

0 commit comments

Comments
 (0)