]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: catch errors in id3parser library 38517/head
authorDaniel Kesselberg <mail@danielkesselberg.de>
Sat, 27 May 2023 22:30:47 +0000 (00:30 +0200)
committerbackportbot-nextcloud[bot] <backportbot-nextcloud[bot]@users.noreply.github.com>
Tue, 30 May 2023 13:45:48 +0000 (13:45 +0000)
We use a forked version of getID3 to read embedded images from mp3 files to use them as previews.

If the library is unable to extract a image or fails on something different we should handle it properly.

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
lib/private/Preview/MP3.php

index 47d752af4771bf1869756fb40e07c024330fff43..ff6ff86c9663dc1cbc709172a895c94b4de6cc7e 100644 (file)
@@ -32,6 +32,7 @@ use ID3Parser\ID3Parser;
 
 use OCP\Files\File;
 use OCP\IImage;
+use Psr\Log\LoggerInterface;
 
 class MP3 extends ProviderV2 {
        /**
@@ -48,8 +49,18 @@ class MP3 extends ProviderV2 {
                $getID3 = new ID3Parser();
 
                $tmpPath = $this->getLocalFile($file);
-               $tags = $getID3->analyze($tmpPath);
-               $this->cleanTmpFiles();
+               try {
+                       $tags = $getID3->analyze($tmpPath);
+               } catch (\Throwable $e) {
+                       \OC::$server->get(LoggerInterface::class)->info($e->getMessage(), [
+                               'exception' => $e,
+                               'app' => 'core',
+                       ]);
+                       return null;
+               } finally {
+                       $this->cleanTmpFiles();
+               }
+
                $picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
                if (is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
                        $picture = $tags['id3v2']['PIC'][0]['data'];