From 5853553455b2795530985537dedd66324af4c5ee Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 7 Sep 2015 17:41:13 +0200 Subject: [PATCH] Make `get fingerprint` slightly more robust against corrupt PDF files This patch adjusts `get fingerprint` to also check that the `/ID` entry contains (non-empty) strings, to prevent more possible failures when loading corrupt PDF files (follow-up to PR 5602). Note that I've not actually encountered such a PDF file in the wild. However given that `stringToBytes` will assert that the input is a string, and that we'll thus fail to load a document unless `get fingerprint` succeeds, making this more robust seems like a good idea to me. --- src/core/core.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/core.js b/src/core/core.js index 21cb72797..e18824877 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -510,12 +510,11 @@ var PDFDocument = (function PDFDocumentClosure() { return shadow(this, 'documentInfo', docInfo); }, get fingerprint() { - var xref = this.xref, idArray, hash, fileID = ''; + var xref = this.xref, hash, fileID = ''; + var idArray = xref.trailer.get('ID'); - if (xref.trailer.has('ID')) { - idArray = xref.trailer.get('ID'); - } - if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) { + if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) && + idArray[0] !== EMPTY_FINGERPRINT) { hash = stringToBytes(idArray[0]); } else { if (this.stream.ensureRange) {