From: Alexander Ebert Date: Fri, 20 Dec 2024 09:53:52 +0000 (+0100) Subject: Add the ability to report damaged images X-Git-Tag: 6.1.3_dev_1~2^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=773b9220a6524a6e95f2fd2be7adb951d31ebeb3;p=GitHub%2FWoltLab%2FWCF.git Add the ability to report damaged images --- diff --git a/wcfsetup/install/files/lib/event/file/GenerateThumbnail.class.php b/wcfsetup/install/files/lib/event/file/GenerateThumbnail.class.php index 790507c369..eaa66057a2 100644 --- a/wcfsetup/install/files/lib/event/file/GenerateThumbnail.class.php +++ b/wcfsetup/install/files/lib/event/file/GenerateThumbnail.class.php @@ -17,6 +17,7 @@ use wcf\system\file\processor\ThumbnailFormat; final class GenerateThumbnail implements IPsr14Event { private string $pathname; + private bool $sourceIsDamaged = false; public function __construct( public readonly File $file, @@ -50,4 +51,18 @@ final class GenerateThumbnail implements IPsr14Event { return $this->pathname ?? null; } + + /** + * Flags the source image as damaged which should stop further processing + * of this file. + */ + public function markSourceAsDamaged(): void + { + $this->sourceIsDamaged = true; + } + + public function sourceIsMarkedAsDamaged(): bool + { + return $this->sourceIsDamaged; + } } diff --git a/wcfsetup/install/files/lib/event/file/GenerateWebpVariant.class.php b/wcfsetup/install/files/lib/event/file/GenerateWebpVariant.class.php index c7f180a437..3ef63b21e2 100644 --- a/wcfsetup/install/files/lib/event/file/GenerateWebpVariant.class.php +++ b/wcfsetup/install/files/lib/event/file/GenerateWebpVariant.class.php @@ -17,6 +17,7 @@ use wcf\event\IPsr14Event; final class GenerateWebpVariant implements IPsr14Event { private string $pathname; + private bool $sourceIsDamaged = false; public function __construct( public readonly File $file @@ -49,4 +50,18 @@ final class GenerateWebpVariant implements IPsr14Event { return $this->pathname ?? null; } + + /** + * Flags the source image as damaged which should stop further processing + * of this file. + */ + public function markSourceAsDamaged(): void + { + $this->sourceIsDamaged = true; + } + + public function sourceIsMarkedAsDamaged(): bool + { + return $this->sourceIsDamaged; + } } diff --git a/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php b/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php index cbd3b336e4..cafc545059 100644 --- a/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php +++ b/wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php @@ -164,6 +164,9 @@ final class FileProcessor extends SingletonFactory $event = new GenerateWebpVariant($file); EventHandler::getInstance()->fire($event); + if ($event->sourceIsMarkedAsDamaged()) { + throw new DamagedImage($file->fileID); + } $filename = $event->getPathname(); if ($filename === null) { @@ -262,6 +265,9 @@ final class FileProcessor extends SingletonFactory $event = new GenerateThumbnail($file, $format); EventHandler::getInstance()->fire($event); + if ($event->sourceIsMarkedAsDamaged()) { + throw new DamagedImage($file->fileID); + } $filename = $event->getPathname(); if ($filename === null) {