瀏覽代碼

Merge pull request #38496 from nextcloud/preview-mp3-catch-errors

fix: catch errors in id3parser library
Simon L 1 年之前
父節點
當前提交
1e1e2fec64
共有 1 個文件被更改,包括 13 次插入2 次删除
  1. 13 2
      lib/private/Preview/MP3.php

+ 13 - 2
lib/private/Preview/MP3.php

@@ -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'];