#110309IMAGE cObject throws TypeError when the referenced file is missing
Description
Problem
When an IMAGE content object references a FAL file whose physical file no longer exists (sys_file.missing = 1), ImageResource::getPublicUrl() returns null. ImageContentObject::cImage() passes that value straight into
@AssetCollector::addMedia(string $fileName, array $additionalInformation)@, which does not accept null:
TypeError: TYPO3\CMS\Core\Page\AssetCollector::addMedia(): Argument #1 ($fileName) must be of type string, null given, called in typo3/sysext/frontend/Classes/ContentObject/ImageContentObject.php on line 79
The TypeError aborts the entire page rendering — the request ends in an HTTP 500, or the ProductionExceptionHandler replaces the whole page content with “Oops, an error occurred!”.
Up to TYPO3 v12 the same situation degraded gracefully: the image was simply skipped and the rest of the page rendered. The regression came with the ImageResource value object introduced in v13 — getImgResource() now
returns a resource object whose public URL may be null, while cImage() only guards against the resource object itself being null:
$imageResource = $this->cObj->getImgResource($file, $conf['file.'] ?? []);
if ($imageResource === null) {
return '';
}
// $info['originalFile'] will be set, when the file is processed by FAL.
// In that case the URL is final and we must not add a prefix
if ($imageResource->getOriginalFile() === null && is_file($imageResource->getFullPath())) {
$absRefPrefix = GeneralUtility::makeInstance(FrontendUrlPrefix::class)->getUrlPrefix($this->request);
$source = $absRefPrefix . str_replace('%2F', '/', rawurlencode($imageResource->getPublicUrl()));
} else {
$source = $imageResource->getPublicUrl(); // may be null
}
GeneralUtility::makeInstance(AssetCollector::class)->addMedia(
$source,
$imageResource->getLegacyImageResourceInformation()
);
Impact
The practical impact is high, because site logos and similar assets are typically rendered on every page through an IMAGE cObject. A single deleted file therefore takes down the complete site, not just the element containing
the image.
Steps to reproduce
- Upload any image via the Filelist module and note its
sys_fileuid (e.g. 42). - Reference it from an IMAGE cObject in the TypoScript setup:
page.10 = IMAGE page.10.file = t3://file?uid=42
- Delete the physical file from disk, but keep the
sys_filerecord:
rm public/fileadmin/<identifier>
- Mark the record as missing — either by running the FAL indexer / the
lowlevelmissing-files detection, or directly:
UPDATE sys_file SET missing = 1 WHERE uid = 42;
- Flush caches and request the page. Instead of a page without the image, the
TypeErrorabove is thrown and the whole page fails.
Step 4 matters: without missing = 1 the file may still resolve to a (dead) URL and render a broken <img> tag rather than crashing.
Affected versions
- main (15.0.0-dev) — affected
- 14.3 — affected, identical code
- 13.4 — affected (verified on 13.4.31); the code differs only in how the
absRefPrefixabove the relevant lines is retrieved ($tsfe->absRefPrefixinstead ofFrontendUrlPrefix)
Suggested fix
Treat a null public URL like an image resource that could not be resolved at all, and return an empty string — restoring the pre-v13 behaviour:
} else {
$source = $imageResource->getPublicUrl();
}
+ // A file whose physical resource is gone (sys_file.missing=1) resolves to
+ // an image resource without public URL. Render nothing in this case, just
+ // like for an image resource that could not be resolved at all.
+ if ($source === null) {
+ return '';
+ }
GeneralUtility::makeInstance(AssetCollector::class)->addMedia(
$source,
$imageResource->getLegacyImageResourceInformation()
);
Alternatives considered:
- Skip only the
addMedia()call and continue rendering — rejected, because the<img>tag would then be rendered with an emptysrcattribute. - Fix deeper, by letting
getImgResource()returnnullwhen the public URL isnull— larger blast radius, since other callers ofgetImgResource()may legitimately work with resources that have no public URL but are
reachable viagetFullPath()(e.g. GIFBUILDER results).
A patch including a functional regression test in ImageContentObjectTest follows on Gerrit.