use wcf\data\object\type\ObjectType;
use wcf\data\object\type\ObjectTypeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
+use wcf\system\exception\SystemException;
+use wcf\system\file\processor\exception\DamagedImage;
use wcf\system\image\adapter\ImageAdapter;
use wcf\system\image\ImageHandler;
use wcf\system\SingletonFactory;
$allowedFileExtensions = \implode(
',',
\array_map(
- static fn (string $fileExtension) => ".{$fileExtension}",
+ static fn(string $fileExtension) => ".{$fileExtension}",
$allowedFileExtensions
)
);
}
$imageAdapter = ImageHandler::getInstance()->getAdapter();
- $imageAdapter->loadFile($file->getPathname());
+
+ try {
+ $imageAdapter->loadFile($file->getPathname());
+ } catch (SystemException) {
+ throw new DamagedImage($file->fileID);
+ }
$filename = FileUtil::getTemporaryFilename(extension: 'webp');
$imageAdapter->saveImageAs($imageAdapter->getImage(), $filename, 'webp', 80);
if ($imageAdapter === null) {
$imageAdapter = ImageHandler::getInstance()->getAdapter();
- $imageAdapter->loadFile($file->getPathname());
+
+ try {
+ $imageAdapter->loadFile($file->getPathname());
+ } catch (SystemException) {
+ throw new DamagedImage($file->fileID);
+ }
}
\assert($imageAdapter instanceof ImageAdapter);
--- /dev/null
+<?php
+
+namespace wcf\system\file\processor\exception;
+
+/**
+ * @author Alexander Ebert
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+final class DamagedImage extends \Exception
+{
+ public function __construct(public readonly int $fileID)
+ {
+ parent::__construct(
+ \sprintf(
+ "The file '%d' is a damaged image.",
+ $this->fileID,
+ ),
+ );
+ }
+}
namespace wcf\system\worker;
+use wcf\data\file\FileEditor;
use wcf\data\file\FileList;
+use wcf\system\file\processor\exception\DamagedImage;
use wcf\system\file\processor\FileProcessor;
+use function wcf\functions\exception\logThrowable;
+
/**
* Worker implementation for updating files.
*
{
parent::execute();
+ $damagedFileIDs = [];
foreach ($this->objectList as $file) {
- FileProcessor::getInstance()->generateWebpVariant($file);
- FileProcessor::getInstance()->generateThumbnails($file);
+ try {
+ FileProcessor::getInstance()->generateWebpVariant($file);
+ FileProcessor::getInstance()->generateThumbnails($file);
+ } catch (DamagedImage $e) {
+ logThrowable($e);
+
+ $damagedFileIDs[] = $e->fileID;
+ }
+ }
+
+ if ($damagedFileIDs !== []) {
+ FileEditor::deleteAll($damagedFileIDs);
}
}
}