From 49af56f73069d50fb5160cefdb4bf1f38f737cb9 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Wed, 22 Mar 2017 14:55:59 +0100 Subject: [PATCH] Rethrow MissingDataException when needed In core/document.js: `PDFDocument.prototype.parse` accesses a dictionary property, which could throw if the underlying data is not yet available. In core/obj.js: `get Catalog.prototype.metadata` calls `stream.getBytes`, which can throw MissingDataException too when the stream is a ChunkedStream. --- src/core/document.js | 3 +++ src/core/obj.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/core/document.js b/src/core/document.js index 69524e480..716b9a21d 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -467,6 +467,9 @@ var PDFDocument = (function PDFDocumentClosure() { } } } catch (ex) { + if (ex instanceof MissingDataException) { + throw ex; + } info('Something wrong with AcroForm entry'); this.acroForm = null; } diff --git a/src/core/obj.js b/src/core/obj.js index c17da2c67..577631801 100644 --- a/src/core/obj.js +++ b/src/core/obj.js @@ -104,6 +104,9 @@ var Catalog = (function CatalogClosure() { try { metadata = stringToUTF8String(bytesToString(stream.getBytes())); } catch (e) { + if (e instanceof MissingDataException) { + throw e; + } info('Skipping invalid metadata.'); } }