Bug #93716
closedProblems with UTF-8 filenames, in cImage the imageLinkWrap gets the public path as identifier
100%
Description
Hi,
we have noticed that there is a problem with uft8 filenames of images when they are processed using imageLinkWrap.
The problem starts in the method TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::getImgResource:
public function getImgResource($file, $fileArray) { ... 'origFile' => $fileObject->getPublicUrl(), // <<<<------ 'origFile_mtime' => $fileObject->getModificationTime(), // This is needed by \TYPO3\CMS\Frontend\Imaging\GifBuilder, // in order for the setup-array to create a unique filename hash. 'originalFile' => $fileObject, 'processedFile' => $processedFileObject ...
The value $info['originalFile'] will be removed later in the method TYPO3\CMS\Frontend\ContentObject\ImageContentObject::cImage:
... // Remove file objects for AssetCollector, as it only allows to store scalar values unset($info['originalFile'], $info['processedFile']); GeneralUtility::makeInstance(AssetCollector::class)->addMedia( $source, $info ); ...
This means that the public path is used to call the imageLinkWrap function in the method TYPO3\CMS\Frontend\ContentObject\ImageContentObject::cImage:
... } elseif ($conf['imageLinkWrap']) { $originalFile = !empty($info['originalFile']) ? $info['originalFile'] : $info['origFile']; $theValue = $this->cObj->imageLinkWrap($theValue, $originalFile, $conf['imageLinkWrap.']); } ...
Which ultimately leads to a fatal result when determining the file object later in the method TYPO3\CMS\Core\Resource\Driver\LocalDriver::getFileInfoByIdentifier:
... $absoluteFilePath = $this->getAbsolutePath($fileIdentifier); // don't use $this->fileExists() because we need the absolute path to the file anyways, so we can directly // use PHP's filesystem method. if (!file_exists($absoluteFilePath) || !is_file($absoluteFilePath)) { throw new \InvalidArgumentException('File ' . $fileIdentifier . ' does not exist.', 1314516809); } ...
A workaround could be that the identifier is urldecoded after it has been entered in the ResourceFactory or that the public path for the array index 'origFile' is not used at all but the real path is used.
Thanks for fixing.
Updated by Lars Michalowski about 3 years ago
Hi,
this bug still exists in the current release 10.4.20. To reproduce this:
1. Activate UTF8 filesystem in install tool by setting [SYS][UTF8filesystem] = true and [SYS][systemLocale] = de_DE.utf-8 (or any other utf8 locale fitting your server configuration).
2. Upload an image file to fileadmin/user_upload/nachhaltig-und-zuverlässig.png
3. Create TS template with:
page = PAGE page.10 = IMAGE page.10 { imageLinkWrap = 1 imageLinkWrap.enable = 1 file = fileadmin/user_upload/nachhaltig-und-zuverlässig.png }
4. Load frontend. This leads to the following exception:
#1314516809 InvalidArgumentException
File /fileadmin/user_upload/nachhaltig-und-zuverl%C3%A4ssig.png does not exist.
5. Set imageLinkWrap = 0 and reload frontend. Image is rendered as expected.
I think a fix of this bug is quite important since it breaks image rendering in the frontend. We can not upgrade to 10.4 at the moment because of this bug.
Updated by Lars Michalowski about 3 years ago
- Related to Bug #90757: ContentObjectRenderer is not able to handle files with Umlauts added
Updated by Lars Michalowski about 3 years ago
This patch worked for me:
--- typo3_src-10.4.20/typo3/sysext/frontend/Classes/ContentObject/ImageContentObject.php 2021-09-07 11:05:57.374679234 +0200
+++ typo3_src-10.4.20-patch/typo3/sysext/frontend/Classes/ContentObject/ImageContentObject.php 2021-09-07 11:08:23.679865925 +0200
@@ -68,6 +68,7 @@
$source = $info[3];
}
// Remove file objects for AssetCollector, as it only allows to store scalar values
+ $infoOriginalFile = $info['originalFile'];
unset($info['originalFile'], $info['processedFile']);
GeneralUtility::makeInstance(AssetCollector::class)->addMedia(
$source,
@@ -104,7 +105,7 @@
if ($linkWrap) {
$theValue = $this->linkWrap($theValue, $linkWrap);
} elseif ($conf['imageLinkWrap']) {
- $originalFile = !empty($info['originalFile']) ? $info['originalFile'] : $info['origFile'];
+ $originalFile = !empty($infoOriginalFile) ? $infoOriginalFile : urldecode($info['origFile']);
$theValue = $this->cObj->imageLinkWrap($theValue, $originalFile, $conf['imageLinkWrap.']);
}
$wrap = isset($conf['wrap.']) ? $this->cObj->stdWrap($conf['wrap'], $conf['wrap.']) : $conf['wrap'];
Updated by Gerrit Code Review over 2 years ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73983
Updated by Christian Kuhn over 2 years ago
- Related to Bug #90565: PageRenderer, Assetcollector - Serialization of Closure is not allowed added
Updated by Gerrit Code Review over 2 years ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73983
Updated by Gerrit Code Review over 2 years ago
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/73983
Updated by Gerrit Code Review over 2 years ago
Patch set 1 for branch 11.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/74116
Updated by Lars Michalowski over 2 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 565a7208fe5ff034f79bff42356eef6ad65aae87.
Updated by Nikita Hovratov over 2 years ago
- Related to Bug #97430: Undefined array key "originalFile" in ImageContentObject added