#109710Bug: FileCollector::addFileReferences() crashes on hidden sys_file_reference records instead of skipping them
Description
Component: typo3/cms-frontend — FileCollector / FilesProcessor Tested with: TYPO3 v13.4.28 Severity: Medium — crashes the entire frontend page render for any visitor
*Summary*
When FilesProcessor resolves file references (e.g. via levelmedia: -1, slide) and one of the resolved sys_file_reference UIDs belongs to a hidden record, FileCollector::addFileReferences() throws an unhandled ResourceDoesNotExistException and crashes the page.
Hidden records are a standard editorial state in TYPO3. They should be silently skipped, not cause a fatal error.
*Steps to reproduce*
Add a file to the media field of a page record (e.g. the root page).
Hide that sys_file_reference record (set hidden = 1) — this can happen when an editor hides a file relation in the backend, or through direct DB manipulation.
On a child page that has no own media file, use a FilesProcessor with references.data = levelmedia: -1, slide so it slides up to the page containing the hidden reference.
Open that child page in the frontend.
Result: Fatal exception, page does not render.
Exception
(1/1) #1317178794 TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException No file reference (sys_file_reference) was found for given UID: "241" in vendor/typo3/cms-core/Classes/Resource/ResourceFactory.php line 405
*Root cause*
ResourceFactory::getFileReferenceObject() uses PageRepository::checkRecord() internally to fetch the reference data. checkRecord() correctly applies frontend enable fields (hidden, etc.) and returns null for hidden records. ResourceFactory then throws ResourceDoesNotExistException (line 405):
// ResourceFactory.php line 397–409
public function getFileReferenceObject(int $uid, ...): FileReference
{
$fileReferenceData = $this->getFileReferenceData($uid, $raw);
if (!is_array($fileReferenceData)) {
throw new ResourceDoesNotExistException( // ← thrown for hidden records
'No file reference (sys_file_reference) was found for given UID: "' . $uid . '"',
1317178794
);
}
}
FileCollector::addFileReferences() has a guard for non-FileInterface returns, but getFileReferenceObject() never returns — it throws. The guard is therefore dead code for this case:
// FileCollector.php line 101–110
public function addFileReferences(array $fileReferenceUids = []): void
{
foreach ($fileReferenceUids as $fileReferenceUid) {
$fileObject = $this->resourceFactory->getFileReferenceObject((int)$fileReferenceUid);
if (!$fileObject instanceof FileInterface) {
continue; // ← never reached; exception was already thrown above
}
$this->addFileObject($fileObject);
}
}
*Expected behaviour*
Hidden sys_file_reference records are inaccessible to the frontend by design. They should be silently skipped, exactly like a non-FileInterface return is already skipped on line 105.
*Suggested fix*
Catch ResourceDoesNotExistException inside the loop in FileCollector::addFileReferences():
public function addFileReferences(array $fileReferenceUids = []): void
{
foreach ($fileReferenceUids as $fileReferenceUid) {
try {
$fileObject = $this->resourceFactory->getFileReferenceObject((int)$fileReferenceUid);
} catch (ResourceDoesNotExistException $e) {
// Reference is hidden, deleted, or otherwise inaccessible to the frontend — skip it.
continue;
}
if (!$fileObject instanceof FileInterface) {
continue;
}
$this->addFileObject($fileObject);
}
}
Alternatively, ResourceFactory::getFileReferenceObject() could return null instead of throwing when the record is not accessible due to enable fields — but that would change the method signature and is a larger change.
Related files- typo3/cms-frontend/Classes/Resource/FileCollector.php line 101–110
- typo3/cms-core/Classes/Resource/ResourceFactory.php line 397–409
Reviews 3
Related issues 1
History 411
-
Gerrit Code Review pushed patch set 1 for main to change 95328 status
NewUnder Review <span data-processor="relativetime" data-value="2026-08-14T07:23:09+00:00" > 08/14/26, 07:23 </span> -
Gerrit Code Review pushed patch set 2 for main to change 95328 <span data-processor="relativetime" data-value="2026-08-16T08:57:21+00:00" > 08/16/26, 08:57 </span>
-
Georg Ringer changed Related to #106906 <span data-processor="relativetime" data-value="2026-08-16T10:44:46+00:00" > 08/16/26, 10:44 </span>
-
Georg Ringer changed Duplicated by #109378 <span data-processor="relativetime" data-value="2026-08-16T12:08:47+00:00" > 08/16/26, 12:08 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 95328 <span data-processor="relativetime" data-value="2026-08-27T15:55:33+00:00" > 08/27/26, 15:55 </span>
-
Gerrit Code Review pushed patch set 1 for 14.3 to change 95528 <span data-processor="relativetime" data-value="2026-09-01T19:42:47+00:00" > 09/01/26, 19:42 </span>
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 95531 <span data-processor="relativetime" data-value="2026-09-01T19:50:14+00:00" > 09/01/26, 19:50 </span>
-
Georg Ringer commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2026-09-01T20:05:09+00:00" > 09/01/26, 20:05 </span> -
Gerrit Code Review pushed patch set 2 for 13.4 to change 95531 status
ResolvedUnder Review <span data-processor="relativetime" data-value="2026-09-01T20:06:14+00:00" > 09/01/26, 20:06 </span> -
Gerrit Code Review pushed patch set 3 for 13.4 to change 95531 <span data-processor="relativetime" data-value="2026-09-01T20:08:33+00:00" > 09/01/26, 20:08 </span>
-
Georg Ringer commented and changed status
Under ReviewResolved <span data-processor="relativetime" data-value="2026-09-01T20:20:09+00:00" > 09/01/26, 20:20 </span>Applied in changeset commit:0d6ef78a9976be40528584e82e7ef6ef9e7f9fd9.
Applied in changeset commit:e53b850618cbad03c82c633c14a65a4fc42c0d13.