Skip to content

Commit

Permalink
BUGFIX: Handle empty files correctly in check
Browse files Browse the repository at this point in the history
  • Loading branch information
kdambekalns authored Nov 18, 2022
1 parent 7a4f80c commit 6aa5888
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions Classes/Service/ThumbnailOptimizationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public function optimizeThumbnail(Thumbnail $thumbnail)
fclose($resourceStream);
fclose($temporaryFileHandle);

$filesizeOriginal = filesize($tmpFileInput);
if ((bool)$filesizeOriginal === false) {
$this->logger->error(sprintf('Creating temporary copy of original image "%s" resulted in empty file', $thumbnail->getOriginalAsset()->getLabel()), $output);
unlink($tmpFileInput);
unlink($tmpFileOptimized);
return;
}

$shellCommand = str_replace(
['{input}', '{output}'],
[escapeshellarg($tmpFileInput), escapeshellarg($tmpFileOptimized)],
Expand All @@ -96,11 +104,9 @@ public function optimizeThumbnail(Thumbnail $thumbnail)
return;
}

$filesizeOriginal = filesize($tmpFileInput);
$filesizeOptimized = filesize($tmpFileOptimized);

if ((bool)$filesizeOriginal === false || (bool)$filesizeOptimized === false) {
$this->logger->error(sprintf('Optimizing image "%s" with command "%s" resulted in empty files', $thumbnail->getOriginalAsset()->getLabel(), $shellCommand), $output);
if ((bool)$filesizeOptimized === false) {
$this->logger->error(sprintf('Optimizing image "%s" with command "%s" resulted in empty file', $thumbnail->getOriginalAsset()->getLabel(), $shellCommand), $output);
unlink($tmpFileInput);
unlink($tmpFileOptimized);
return;
Expand Down

0 comments on commit 6aa5888

Please sign in to comment.