Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't render corrupted inlined images #17795

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 30 additions & 21 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions test/pdfs/issue17794.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
https://github.com/mozilla/pdf.js/files/14607428/image1.pdf

8 changes: 8 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9771,5 +9771,13 @@
"rounds": 1,
"annotations": true,
"type": "eq"
},
{
"id": "issue17794",
"file": "pdfs/issue17794.pdf",
"md5": "a66b5b938cb44ae241cad845cc3b5d2d",
"rounds": 1,
"link": true,
"type": "eq"
}
]