From 773b9220a6524a6e95f2fd2be7adb951d31ebeb3 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 20 Dec 2024 10:53:52 +0100 Subject: [PATCH] Add the ability to report damaged images --- .../lib/event/file/GenerateThumbnail.class.php | 15 +++++++++++++++ .../lib/event/file/GenerateWebpVariant.class.php | 15 +++++++++++++++ .../system/file/processor/FileProcessor.class.php | 6 ++++++ 3 files changed, 36 insertions(+) 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) { -- 2.20.1