Project

General

Profile

Actions

Bug #93345

open

Exception when image with 0 bytes is used for click enlarge

Added by Torben Hansen over 3 years ago. Updated over 2 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Frontend
Target version:
-
Start date:
2021-01-22
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

This edge case issue occurred after a TYPO3 8.7 to 10.4 migration.

How to reproduce:

  • TypoScript Constant styles.content.textmedia.linkWrap.lightboxEnabled = 1 must be set
  • User uploads an image file test.jpg which has a size of 0 bytes
  • User uses the uploaded image in a image content element
  • User sets the file width or height in the content element to a various integer (e.g. 100)
  • User selects the "Click-Enlarge" option

Opening the page with the image content element will result in an exception.

PHP Catchable Fatal Error: Object of class TYPO3\CMS\Core\Resource\FileReference could not be converted to string in /path/to/typo3/typo3_src-10.4.12/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php line 4454

Reason:
https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php#L3999

isImage() returns false since the file is 0 bytes and then the FilePathSanitizer tries to typecast the file variable (which is a FileReference) to a string.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #87784: ClickEnlargeViewHelper causes error "Object of class FileReference could not be converted to string in TemplateService.php line 1441"Closed2019-02-25

Actions
Actions #1

Updated by Jan Epper about 3 years ago

This seems to be the same or a similar bug like #87784. According to Adrian Dymorz from #87784 the issue disapperead so the issue has been closed and then reappeared again. I've recently also ran into this problem. If you replace the following code like Adrian Dymorz described it works again. But it's not peramanent since the fix can be overwritten by an update. Unfortunatelly I'm not sure how to write a patch for this issue.

Here is the code that has to be replaced in file:
https://github.com/TYPO3/TYPO3.CMS/blob/189e065f957762283aa8d790c4a1c19d763c0eb8/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php#L4454

Old code:

$theImage = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize((string)$file);

New code:

if ($file instanceof FileReference) {
    $fileAsString = $file->getForLocalProcessing(false);
} else {
    $fileAsString = $file;
}
$theImage = GeneralUtility::makeInstance(FilePathSanitizer::class)->sanitize((string)$fileAsString);

Thanks to Adrian Dymorz for the solution

Actions #2

Updated by Jan Epper about 3 years ago

  • Related to Bug #87784: ClickEnlargeViewHelper causes error "Object of class FileReference could not be converted to string in TemplateService.php line 1441" added
Actions #3

Updated by B. Kausch over 2 years ago

Is there any chance this can be fixed? This bug is a nightmare, breaking the entire site after an upgrade...

Actions

Also available in: Atom PDF