Don't render corrupted inlined images

Fixes #17794.
This commit is contained in:
Calixte Denizet 2024-03-14 21:23:26 +01:00
parent 30e69956db
commit 9c3471dd01
3 changed files with 40 additions and 21 deletions

View file

@ -739,27 +739,36 @@ class PartialEvaluator {
!dict.has("Mask") && !dict.has("Mask") &&
w + h < SMALL_IMAGE_DIMENSIONS w + h < SMALL_IMAGE_DIMENSIONS
) { ) {
const imageObj = new PDFImage({ try {
xref: this.xref, const imageObj = new PDFImage({
res: resources, xref: this.xref,
image, res: resources,
isInline, image,
pdfFunctionFactory: this._pdfFunctionFactory, isInline,
localColorSpaceCache, pdfFunctionFactory: this._pdfFunctionFactory,
}); localColorSpaceCache,
// We force the use of RGBA_32BPP images here, because we can't handle });
// any other kind. // We force the use of RGBA_32BPP images here, because we can't handle
imgData = await imageObj.createImageData( // any other kind.
/* forceRGBA = */ true, imgData = await imageObj.createImageData(
/* isOffscreenCanvasSupported = */ false /* forceRGBA = */ true,
); /* isOffscreenCanvasSupported = */ false
operatorList.isOffscreenCanvasSupported = );
this.options.isOffscreenCanvasSupported; operatorList.isOffscreenCanvasSupported =
operatorList.addImageOps( this.options.isOffscreenCanvasSupported;
OPS.paintInlineImageXObject, operatorList.addImageOps(
[imgData], OPS.paintInlineImageXObject,
optionalContent [imgData],
); optionalContent
);
} catch (reason) {
const msg = `Unable to decode inline image: "${reason}".`;
if (!this.options.ignoreErrors) {
throw new Error(msg);
}
warn(msg);
}
return; return;
} }

View file

@ -0,0 +1,2 @@
https://github.com/mozilla/pdf.js/files/14607428/image1.pdf

View file

@ -9771,5 +9771,13 @@
"rounds": 1, "rounds": 1,
"annotations": true, "annotations": true,
"type": "eq" "type": "eq"
},
{
"id": "issue17794",
"file": "pdfs/issue17794.pdf",
"md5": "a66b5b938cb44ae241cad845cc3b5d2d",
"rounds": 1,
"link": true,
"type": "eq"
} }
] ]