From 9c3471dd01bdc9ee35c659caecc89d33556cbce8 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 14 Mar 2024 21:23:26 +0100 Subject: [PATCH] Don't render corrupted inlined images Fixes #17794. --- src/core/evaluator.js | 51 ++++++++++++++++++++--------------- test/pdfs/issue17794.pdf.link | 2 ++ test/test_manifest.json | 8 ++++++ 3 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 test/pdfs/issue17794.pdf.link diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 32a2ece7a8ab5..9d5ad52db1020 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -739,27 +739,36 @@ class PartialEvaluator { !dict.has("Mask") && w + h < SMALL_IMAGE_DIMENSIONS ) { - const imageObj = new PDFImage({ - xref: this.xref, - res: resources, - image, - isInline, - pdfFunctionFactory: this._pdfFunctionFactory, - localColorSpaceCache, - }); - // We force the use of RGBA_32BPP images here, because we can't handle - // any other kind. - imgData = await imageObj.createImageData( - /* forceRGBA = */ true, - /* isOffscreenCanvasSupported = */ false - ); - operatorList.isOffscreenCanvasSupported = - this.options.isOffscreenCanvasSupported; - operatorList.addImageOps( - OPS.paintInlineImageXObject, - [imgData], - optionalContent - ); + try { + const imageObj = new PDFImage({ + xref: this.xref, + res: resources, + image, + isInline, + pdfFunctionFactory: this._pdfFunctionFactory, + localColorSpaceCache, + }); + // We force the use of RGBA_32BPP images here, because we can't handle + // any other kind. + imgData = await imageObj.createImageData( + /* forceRGBA = */ true, + /* isOffscreenCanvasSupported = */ false + ); + operatorList.isOffscreenCanvasSupported = + this.options.isOffscreenCanvasSupported; + operatorList.addImageOps( + OPS.paintInlineImageXObject, + [imgData], + optionalContent + ); + } catch (reason) { + const msg = `Unable to decode inline image: "${reason}".`; + + if (!this.options.ignoreErrors) { + throw new Error(msg); + } + warn(msg); + } return; } diff --git a/test/pdfs/issue17794.pdf.link b/test/pdfs/issue17794.pdf.link new file mode 100644 index 0000000000000..e243f87647036 --- /dev/null +++ b/test/pdfs/issue17794.pdf.link @@ -0,0 +1,2 @@ +https://github.com/mozilla/pdf.js/files/14607428/image1.pdf + diff --git a/test/test_manifest.json b/test/test_manifest.json index d00a9856a6780..3fd5ba0c5a1a3 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -9771,5 +9771,13 @@ "rounds": 1, "annotations": true, "type": "eq" + }, + { + "id": "issue17794", + "file": "pdfs/issue17794.pdf", + "md5": "a66b5b938cb44ae241cad845cc3b5d2d", + "rounds": 1, + "link": true, + "type": "eq" } ]