Skip to content
Snippets Groups Projects
Commit 1da73366 authored by Nikita Hovratov's avatar Nikita Hovratov Committed by Stefan Bürk
Browse files

[BUGFIX] Handle missing image dimensions gracefully

Just like SvgImageProcessor, DeferredBackendImageProcessor now also
catches the exception, which is thrown, when image dimensions equal
zero and falls back to 64x64 image dimension. This enables editors to
correct bad image cropping without the need to do it in the database.

To be more specific, a new Exception ZeroImageDimensionException is
added, which is used in both processors now.

The image cropping editor is already fixed to only allow a minimum
dimension of 10x10. However, already corrupted files can not be
accessed without this patch.

Resolves: #93807
Related: #99943
Releases: main, 12.4, 11.5
Change-Id: I259c365052dd02110d43418ba48b768bbe073fc1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81133


Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarcore-ci <typo3@b13.com>
parent a5b39ef2
Branches
Tags
No related merge requests found
......@@ -21,6 +21,7 @@ use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Imaging\Exception\ZeroImageDimensionException;
use TYPO3\CMS\Core\Imaging\ImageDimension;
use TYPO3\CMS\Core\Resource\ProcessedFileRepository;
use TYPO3\CMS\Core\Resource\Processing\ProcessorInterface;
......@@ -48,7 +49,12 @@ class DeferredBackendImageProcessor implements ProcessorInterface
public function processTask(TaskInterface $task): void
{
$imageDimension = ImageDimension::fromProcessingTask($task);
try {
$imageDimension = ImageDimension::fromProcessingTask($task);
} catch (ZeroImageDimensionException $e) {
// To not fail image processing, we just assume an image dimension here
$imageDimension = new ImageDimension(64, 64);
}
$processedFile = $task->getTargetFile();
if (!$processedFile->isPersisted()) {
// For now, we need to persist the processed file in the repository to be able to reference its uid
......
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Imaging\Exception;
use TYPO3\CMS\Core\Exception;
/**
* This exception is thrown when an image is tasked to be processed with
* dimensions of zero.
*/
class ZeroImageDimensionException extends Exception
{
}
......@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Imaging;
use TYPO3\CMS\Core\Imaging\Exception\ZeroImageDimensionException;
use TYPO3\CMS\Core\Imaging\ImageManipulation\Area;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Resource\Processing\LocalPreviewHelper;
......@@ -73,7 +74,7 @@ class ImageDimension
);
}
if ($imageDimension->width <= 0 || $imageDimension->height <= 0) {
throw new \BadMethodCallException('Width and height of the image must be greater than zero', 1597310560);
throw new ZeroImageDimensionException('Width and height of the image must be greater than zero.', 1597310560);
}
$result = GeneralUtility::makeInstance(GraphicalFunctions::class)->getImageScale(
[
......
......@@ -17,6 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Resource\Processing;
use TYPO3\CMS\Core\Imaging\Exception\ZeroImageDimensionException;
use TYPO3\CMS\Core\Imaging\ImageDimension;
/**
......@@ -44,7 +45,7 @@ class SvgImageProcessor implements ProcessorInterface
$task->getTargetFile()->setUsesOriginalFile();
try {
$imageDimension = ImageDimension::fromProcessingTask($task);
} catch (\Throwable $e) {
} catch (ZeroImageDimensionException $e) {
// To not fail image processing, we just assume an SVG image dimension here
$imageDimension = new ImageDimension(64, 64);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment