Ensure that PDFImage.buildImage won't accidentally swallow errors, e.g. from ColorSpace parsing (issue 6707, PR 11601 follow-up)

Because of a really stupid `Promise`-related mistake on my part, when re-factoring `PDFImage.buildImage` during the `NativeImageDecoder` removal, we're no longer re-throwing errors occuring during image parsing/decoding as intended.
The result is that some (fairly) corrupt documents will never finish loading, and unfortunately there were apparently no sufficiently corrupt images in the test-suite to catch this.
This commit is contained in:
Jonas Jenwald 2020-06-13 14:41:34 +02:00
parent c809f00b3b
commit 4b51bcc733
4 changed files with 21 additions and 13 deletions

View File

@ -579,7 +579,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
return this._sendImgData(objId, imgData, cacheGlobally); return this._sendImgData(objId, imgData, cacheGlobally);
}) })
.catch(reason => { .catch(reason => {
warn("Unable to decode image: " + reason); warn(`Unable to decode image "${objId}": "${reason}".`);
return this._sendImgData(objId, /* imgData = */ null, cacheGlobally); return this._sendImgData(objId, /* imgData = */ null, cacheGlobally);
}); });

View File

@ -248,7 +248,7 @@ var PDFImage = (function PDFImageClosure() {
* Handles processing of image data and returns the Promise that is resolved * Handles processing of image data and returns the Promise that is resolved
* with a PDFImage when the image is ready to be used. * with a PDFImage when the image is ready to be used.
*/ */
PDFImage.buildImage = function ({ PDFImage.buildImage = async function ({
xref, xref,
res, res,
image, image,
@ -271,17 +271,16 @@ var PDFImage = (function PDFImageClosure() {
warn("Unsupported mask format."); warn("Unsupported mask format.");
} }
} }
return Promise.resolve(
new PDFImage({ return new PDFImage({
xref, xref,
res, res,
image: imageData, image: imageData,
isInline, isInline,
smask: smaskData, smask: smaskData,
mask: maskData, mask: maskData,
pdfFunctionFactory, pdfFunctionFactory,
}) });
);
}; };
PDFImage.createMask = function ({ PDFImage.createMask = function ({

View File

@ -0,0 +1 @@
https://web.archive.org/web/20151201202008/https://secure.dynaccount.com/data/voucher/30000/400/30452_93e074c4c8b2301a24b33176331c49e5755e02fa.pdf

View File

@ -669,6 +669,14 @@
"lastPage": 1, "lastPage": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "issue6707",
"file": "pdfs/issue6707.pdf",
"md5": "068ceaec23d265b1d38dfa6ab279f017",
"rounds": 1,
"link": true,
"lastPage": 1,
"type": "eq"
},
{ "id": "issue6721_reduced", { "id": "issue6721_reduced",
"file": "pdfs/issue6721_reduced.pdf", "file": "pdfs/issue6721_reduced.pdf",
"md5": "719aa66d8081a15e3ba6032ed4279237", "md5": "719aa66d8081a15e3ba6032ed4279237",