From 381a45cad4187ebe2afc565d601e7f54b8003bb4 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 | 46 +++++++++++++++++++---------------- test/pdfs/issue17794.pdf.link | 2 ++ test/test_manifest.json | 8 ++++++ 3 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 test/pdfs/issue17794.pdf.link diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 32a2ece7a8ab52..4a9590b593f0a6 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -739,27 +739,31 @@ 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) { + warn(`Unable to decode inline image: "${reason}".`); + } return; } diff --git a/test/pdfs/issue17794.pdf.link b/test/pdfs/issue17794.pdf.link new file mode 100644 index 00000000000000..e243f87647036e --- /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 d00a9856a67806..3fd5ba0c5a1a34 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" } ]