Issue Bug Closed

#93345Exception when image with 0 bytes is used for click enlarge

Torben Hansen 01/22/21, 10:38 updated 12/02/25, 14:33

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.

Reviews 2

History 1013

  1. Jan Epper commented <span data-processor="relativetime" data-value="2021-04-10T11:40:40+00:00" > 04/10/21, 11:40 </span>

    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

  2. B. Kausch commented <span data-processor="relativetime" data-value="2021-09-09T14:36:02+00:00" > 09/09/21, 14:36 </span>

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

  3. Benni Mack commented and changed status Under Review Needs Feedback <span data-processor="relativetime" data-value="2025-04-10T09:31:07+00:00" > 04/10/25, 09:31 </span>

    This has been fixed in v13. Can anyone confirm?

  4. Torben Hansen commented <span data-processor="relativetime" data-value="2025-04-11T07:23:21+00:00" > 04/11/25, 07:23 </span>

    @benni I have tested the scenario following the steops from my initial report with TYPO3 v12 and v13, and the problem still persists.

  5. Benni Mack commented <span data-processor="relativetime" data-value="2025-04-11T07:24:11+00:00" > 04/11/25, 07:24 </span>

    Torben Hansen wrote in #note-6:
    > @benni I have tested the scenario following the steops from my initial report with TYPO3 v12 and v13, and the problem still persists.

    Hey Torben,

    can you provide a patch then? I feel like I’m missing something to reproduce this.

  6. Gerrit Code Review pushed patch set 2 for main to change 88895 status Needs Feedback Under Review <span data-processor="relativetime" data-value="2025-04-11T16:56:48+00:00" > 04/11/25, 16:56 </span>

  7. Georg Ringer commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-04-11T17:20:07+00:00" > 04/11/25, 17:20 </span>

    Applied in changeset commit:7b406b0e334ab4a96f31087eddd1e71f085376b5.