#110137Image processing stores a 0-byte / invalid result as a successful ProcessedFile
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
History 2
-
Garvin Hicking commented and changed status
NewNeeds Feedback <span data-processor="relativetime" data-value="2026-07-01T19:49:59+00:00" > 07/01/26, 19:49 </span> -
Benjamin Blanck commented <span data-processor="relativetime" data-value="2026-07-02T09:09:54+00:00" > 07/02/26, 09:09 </span>
Having thought it through (and tested it), the fix I proposed in the report doesn’t hold up: with
setExecuted(false)(“just reprocess on the next request”), a conversion that fails deterministically would simply run again on every single page hit.When
imageMagickConvert()returnsnull, the core already falls back gracefully:setUsesOriginalFile()is persisted. An empty file bypasses exactly that, because the success check is a barefile_exists(): the 0-byte result is cached as if it were a valid thumbnail. Treating “exists but empty” like “no result at all”, drop the leftover file, fall back tosetUsesOriginalFile()keeps the caching semantics as intended and just swaps the permanently broken image for the original.Admittedly, the original-file fallback isn’t great either: nobody notices, and the “fallback” can be a huge file shipped to every visitor…
How would you prevent then, that your page would try to create a thumbnail every request again and again? It can never complete.
I’d argue that this is actually a safety net for a misbehaving I/GM instance, and you should probably ensure all image checks succeed?
Or would you expect a “broken image” pseudo thumbnail to be assigned to it? That would then imply how to render that thumbnail, how should it look like? Should it have the target dimensions or fixed dimensions? There are a lot of followup scenarios to take into consideration.
(I’m just stating this to fuel discussion, I’m not denying this can be an issue – but it’s deeper than one might think)