Issue Bug Resolved

#109710Bug: FileCollector::addFileReferences() crashes on hidden sys_file_reference records instead of skipping them

Thomas Sam Wittich 04/25/26, 12:46 updated 09/01/26, 20:20

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

History 411

  1. Georg Ringer commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-09-01T20:05:09+00:00" > 09/01/26, 20:05 </span>

    Applied in changeset commit:e53b850618cbad03c82c633c14a65a4fc42c0d13.

  2. Gerrit Code Review pushed patch set 2 for 13.4 to change 95531 status Resolved Under Review <span data-processor="relativetime" data-value="2026-09-01T20:06:14+00:00" > 09/01/26, 20:06 </span>

  3. Georg Ringer commented and changed status Under Review Resolved <span data-processor="relativetime" data-value="2026-09-01T20:20:09+00:00" > 09/01/26, 20:20 </span>

    Applied in changeset commit:0d6ef78a9976be40528584e82e7ef6ef9e7f9fd9.