Issue Bug Needs Feedback Stale

#110137Image processing stores a 0-byte / invalid result as a successful ProcessedFile

Benjamin Blanck 07/01/26, 13:45 updated 07/02/26, 09:09

Description

Summary

When the image processor (GraphicsMagick/ImageMagick) does not produce a valid output but leaves a 0-byte file behind, TYPO3 treats the run as successful — it only checks `file_exists()`, never the file’s validity/size — creates a `sys_file_processedfile` record for it, and then serves that 0-byte file on every subsequent request.

A single transient processing failure therefore turns into a permanently cached, broken image until the processed-files cache is cleared or the original file changes. This is why it typically shows up as “images are sometimes broken, sometimes not”.

Trigger

The output is empty whenever the underlying CLI run fails after (partially) creating the target file. GM/IM does exactly this on a WebP encode error: it leaves a 0-byte target file.

A reliable, deterministic trigger is a WebP output whose width or height exceeds libwebp’s hard limit of 16383 px — GM/IM aborts with `width or height exceeds limit` but leaves a 0-byte file. In production the same empty output also occurs from transient failures under load (resource contention), which is the “sometimes” case.

Steps to reproduce

1. Put a source image wider than 16383 px into a storage, e.g. `fileadmin/wide.png` (17000×1000):

gm convert -size 17000x1000 xc:teal fileadmin/wide.png

2. Process it to WebP at original size (so the result is 17000 px wide → exceeds the libwebp limit):

   $file = $storage->getFile('/wide.png');
   $processed = $file->process(
       \TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGECROPSCALEMASK,
       ['width' => '', 'height' => '', 'fileExtension' => 'webp']
   );

Actual result (TYPO3 13.4)

isProcessed       = 1
usesOriginalFile  = 0
name              = csm_wide_<hash>.webp
exists            = 1
size              = 0          <-- empty file
width / height    = 0 / 0

- A `sys_file_processedfile` row is created (width=0, height=0).
- A second `process()` call returns the same cached 0-byte file (no reprocessing) → the failure is sticky.
- The rendered `` points to a 0-byte `.webp` → broken image, permanently, until the processed-files cache is cleared.

Expected result

A run that did not produce a valid image must not be treated as successful and must not be persisted as a ProcessedFile. The invalid result should be discarded (so the next request reprocesses) and/or the original file used as fallback — a 0-byte file should never be cached and served.

Root cause

`TYPO3\CMS\Core\Resource\Processing\LocalImageProcessor::processTaskWithLocalFile()` decides success purely on file existence (TYPO3 13.4, ~line 69):

} elseif (!empty($result['filePath']) && file_exists($result['filePath'])) {
    $task->setExecuted(true);
    $imageInformation = GeneralUtility::makeInstance(ImageInfo::class, $result['filePath']);
    // ...
    $task->getTargetFile()->updateProperties([
        'width'  => $imageInformation->getWidth(),   // 0 for an empty file
        'height' => $imageInformation->getHeight(),  // 0
        'size'   => $imageInformation->getSize(),     // 0
        'checksum' => $task->getConfigurationChecksum(),
    ]);
    $task->getTargetFile()->updateWithLocalFile($result['filePath']);
}

A 0-byte file “exists”, so the task is marked executed/successful and the (zero) dimensions are stored without being validated. `FileProcessingService::processFile()` then persists it because the task reports success (TYPO3 13.4, ~line 78):

if ($task->isExecuted() && $task->isSuccessful() && $processedFile->isProcessed()) {
    $this->processedFileRepository->add($processedFile);
}

(`GraphicalFunctions::imageMagickConvert()` likewise returns the target as a result based on `file_exists()`, so the empty file reaches the processor as a “result” in the first place.)

Proposed fix

Validate the produced file before marking the task successful — the needed data (`ImageInfo`) is already available at that spot. In `LocalImageProcessor::processTaskWithLocalFile()`:

} elseif (
    !empty($result['filePath'])
    && file_exists($result['filePath'])
    && filesize($result['filePath']) > 0
) {
    $task->setExecuted(true);
    $imageInformation = GeneralUtility::makeInstance(ImageInfo::class, $result['filePath']);
    if ($imageInformation->getWidth() === 0 || $imageInformation->getHeight() === 0) {
        // produced file is not a valid image -> do not cache, retry next time
        $task->setExecuted(false);
        return;
    }
    // ... existing success handling ...
} else {
    // no valid processing result
    $task->setExecuted(false);
}

With `setExecuted(false)` the result is not persisted; the next request reprocesses and no broken file is ever served.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch

Commit message
[BUGFIX] Image processing stores a 0-byte / invalid result as a successful ProcessedFile Resolves: #110137 Releases: main