Skip to content

Commit 773b922

Browse files
committed
Add the ability to report damaged images
1 parent 75a6040 commit 773b922

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

wcfsetup/install/files/lib/event/file/GenerateThumbnail.class.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
final class GenerateThumbnail implements IPsr14Event
1818
{
1919
private string $pathname;
20+
private bool $sourceIsDamaged = false;
2021

2122
public function __construct(
2223
public readonly File $file,
@@ -50,4 +51,18 @@ public function getPathname(): ?string
5051
{
5152
return $this->pathname ?? null;
5253
}
54+
55+
/**
56+
* Flags the source image as damaged which should stop further processing
57+
* of this file.
58+
*/
59+
public function markSourceAsDamaged(): void
60+
{
61+
$this->sourceIsDamaged = true;
62+
}
63+
64+
public function sourceIsMarkedAsDamaged(): bool
65+
{
66+
return $this->sourceIsDamaged;
67+
}
5368
}

wcfsetup/install/files/lib/event/file/GenerateWebpVariant.class.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
final class GenerateWebpVariant implements IPsr14Event
1818
{
1919
private string $pathname;
20+
private bool $sourceIsDamaged = false;
2021

2122
public function __construct(
2223
public readonly File $file
@@ -49,4 +50,18 @@ public function getPathname(): ?string
4950
{
5051
return $this->pathname ?? null;
5152
}
53+
54+
/**
55+
* Flags the source image as damaged which should stop further processing
56+
* of this file.
57+
*/
58+
public function markSourceAsDamaged(): void
59+
{
60+
$this->sourceIsDamaged = true;
61+
}
62+
63+
public function sourceIsMarkedAsDamaged(): bool
64+
{
65+
return $this->sourceIsDamaged;
66+
}
5267
}

wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ public function generateWebpVariant(File $file): void
164164

165165
$event = new GenerateWebpVariant($file);
166166
EventHandler::getInstance()->fire($event);
167+
if ($event->sourceIsMarkedAsDamaged()) {
168+
throw new DamagedImage($file->fileID);
169+
}
167170

168171
$filename = $event->getPathname();
169172
if ($filename === null) {
@@ -262,6 +265,9 @@ public function generateThumbnails(File $file): void
262265

263266
$event = new GenerateThumbnail($file, $format);
264267
EventHandler::getInstance()->fire($event);
268+
if ($event->sourceIsMarkedAsDamaged()) {
269+
throw new DamagedImage($file->fileID);
270+
}
265271

266272
$filename = $event->getPathname();
267273
if ($filename === null) {

0 commit comments

Comments
 (0)