From ef00e9659790d5b9249375c6663fcf73ea366674 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 1 Jan 2025 12:29:20 -0500 Subject: [PATCH] chore(Previews): make thumbnail generation more robust Signed-off-by: Josh --- lib/private/Preview/Image.php | 8 ++++++++ lib/private/Preview/MP3.php | 8 ++++++++ lib/private/Preview/Movie.php | 7 +++++++ lib/private/Preview/Office.php | 8 ++++++++ 4 files changed, 31 insertions(+) diff --git a/lib/private/Preview/Image.php b/lib/private/Preview/Image.php index 69841f079296e..8b970258b4591 100644 --- a/lib/private/Preview/Image.php +++ b/lib/private/Preview/Image.php @@ -9,6 +9,7 @@ use OCP\Files\File; use OCP\IImage; +use Psr\Log\LoggerInterface; abstract class Image extends ProviderV2 { /** @@ -25,6 +26,13 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { $image = new \OCP\Image(); $fileName = $this->getLocalFile($file); + if ($fileName === false) { + \OCP\Server::get(LoggerInterface::class)->error( + 'Failed to get thumbnail for: ' . $file->getPath(), + ['app' => 'core'] + ); + return null; + } $image->loadFromFile($fileName); $image->fixOrientation(); diff --git a/lib/private/Preview/MP3.php b/lib/private/Preview/MP3.php index 105b182b415ae..c2cd0750063e1 100644 --- a/lib/private/Preview/MP3.php +++ b/lib/private/Preview/MP3.php @@ -9,6 +9,7 @@ use OCP\Files\File; use OCP\IImage; +use Psr\Log\LoggerInterface; use wapmorgan\Mp3Info\Mp3Info; use function OCP\Log\logger; @@ -25,6 +26,13 @@ public function getMimeType(): string { */ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { $tmpPath = $this->getLocalFile($file); + if ($tmpPath === false) { + \OCP\Server::get(LoggerInterface::class)->error( + 'Failed to get thumbnail for: ' . $file->getPath(), + ['app' => 'core'] + ); + return null; + } try { $audio = new Mp3Info($tmpPath, true); diff --git a/lib/private/Preview/Movie.php b/lib/private/Preview/Movie.php index 4a6104930d6f5..d49c547bcf010 100644 --- a/lib/private/Preview/Movie.php +++ b/lib/private/Preview/Movie.php @@ -75,6 +75,13 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { foreach ($sizeAttempts as $size) { $absPath = $this->getLocalFile($file, $size); + if ($absPath === false) { + \OCP\Server::get(LoggerInterface::class)->error( + 'Failed to get thumbnail for: ' . $file->getPath(), + ['app' => 'core'] + ); + return null; + } $result = null; if (is_string($absPath)) { diff --git a/lib/private/Preview/Office.php b/lib/private/Preview/Office.php index 20fbef6eb23eb..c3126276c9c7a 100644 --- a/lib/private/Preview/Office.php +++ b/lib/private/Preview/Office.php @@ -12,6 +12,7 @@ use OCP\IImage; use OCP\ITempManager; use OCP\Server; +use Psr\Log\LoggerInterface; abstract class Office extends ProviderV2 { /** @@ -33,6 +34,13 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage { // The file to generate the preview for. $absPath = $this->getLocalFile($file); + if ($absPath === false) { + \OCP\Server::get(LoggerInterface::class)->error( + 'Failed to get thumbnail for: ' . $file->getPath(), + ['app' => 'core'] + ); + return null; + } // The destination for the LibreOffice user profile. // LibreOffice can rune once per user profile and therefore instance id and file id are included.