From 359a2752d80e9734e7d3cd0147b1a86ab348053b Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 21 Apr 2024 15:07:53 -0500 Subject: [PATCH] Fix:Server crash when scanning in invalid epub #2856 --- server/utils/parsers/parseEpubMetadata.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/utils/parsers/parseEpubMetadata.js b/server/utils/parsers/parseEpubMetadata.js index 4733004689..bee1e8de6a 100644 --- a/server/utils/parsers/parseEpubMetadata.js +++ b/server/utils/parsers/parseEpubMetadata.js @@ -18,7 +18,10 @@ async function extractFileFromEpub(epubPath, filepath) { Logger.error(`[parseEpubMetadata] Failed to extract ${filepath} from epub at "${epubPath}"`, error) }) const filedata = data?.toString('utf8') - await zip.close() + await zip.close().catch((error) => { + Logger.error(`[parseEpubMetadata] Failed to close zip`, error) + }) + return filedata } @@ -68,6 +71,9 @@ async function parse(ebookFile) { Logger.debug(`Parsing metadata from epub at "${epubPath}"`) // Entrypoint of the epub that contains the filepath to the package document (opf file) const containerJson = await extractXmlToJson(epubPath, 'META-INF/container.xml') + if (!containerJson) { + return null + } // Get package document opf filepath from container.xml const packageDocPath = containerJson.container?.rootfiles?.[0]?.rootfile?.[0]?.$?.['full-path']