From b44a975d7cfeabf63e1462affe826b5261eb73bf Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 22 Oct 2020 13:24:43 +0200 Subject: [PATCH] Prevent issues, in `PDFDocument.fieldObjects`, for invalid Annotations For an invalid Annotation, there's one code-path where `undefined` is returned from `AnnotationFactory._create`. That'd currently, incorrectly, trigger an error during the `PDFDocument._collectFieldObjects` parsing which thus seem good to avoid. Along these lines, the filtering in `PDFDocument.fieldObjects` is also updated to handle both `null` and `undefined` the same way. --- src/core/document.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/document.js b/src/core/document.js index 105ea1a71..cb9e474d3 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -969,7 +969,7 @@ class PDFDocument { this.pdfManager, this._localIdFactory ) - .then(annotation => annotation.getFieldObject()) + .then(annotation => annotation && annotation.getFieldObject()) .catch(function (reason) { warn(`_collectFieldObjects: "${reason}".`); return null; @@ -999,7 +999,7 @@ class PDFDocument { for (const [name, promises] of fieldPromises) { allPromises.push( Promise.all(promises).then(fields => { - fields = fields.filter(field => field !== null); + fields = fields.filter(field => !!field); if (fields.length > 0) { allFields[name] = fields; }