diff --git a/src/core/document.js b/src/core/document.js index c89078d90dfe2..2d6328af4ed55 100644 --- a/src/core/document.js +++ b/src/core/document.js @@ -132,10 +132,12 @@ class Page { // For robustness: The spec states that a \Resources entry has to be // present, but can be empty. Some documents still omit it; in this case // we return an empty dictionary. + const resources = this._getInheritableProperty("Resources"); + return shadow( this, "resources", - this._getInheritableProperty("Resources") || Dict.empty + resources instanceof Dict ? resources : Dict.empty ); } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index f71f69d377b83..2c0abecc028b3 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -509,6 +509,7 @@ !poppler-67295-0.pdf !poppler-85140-0.pdf !issue15012.pdf +!issue15150.pdf !poppler-395-0-fuzzed.pdf !GHOSTSCRIPT-698804-1-fuzzed.pdf !issue14814.pdf diff --git a/test/pdfs/issue15150.pdf b/test/pdfs/issue15150.pdf new file mode 100644 index 0000000000000..c332caf2b4487 Binary files /dev/null and b/test/pdfs/issue15150.pdf differ diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js index e9eb7c59ef4f1..f932ec378766a 100644 --- a/test/unit/api_spec.js +++ b/test/unit/api_spec.js @@ -673,6 +673,38 @@ describe("api", function () { await Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]); }); + + it("creates pdf doc from PDF file with bad /Resources entry", async function () { + const loadingTask = getDocument(buildGetDocumentParams("issue15150.pdf")); + expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true); + + const pdfDocument = await loadingTask.promise; + expect(pdfDocument.numPages).toEqual(1); + + const page = await pdfDocument.getPage(1); + expect(page instanceof PDFPageProxy).toEqual(true); + + const opList = await page.getOperatorList(); + expect(opList.fnArray).toEqual([ + OPS.setLineWidth, + OPS.setStrokeRGBColor, + OPS.constructPath, + OPS.closeStroke, + ]); + expect(opList.argsArray).toEqual([ + [0.5], + new Uint8ClampedArray([255, 0, 0]), + [ + [OPS.moveTo, OPS.lineTo], + [0, 9.75, 0.5, 9.75], + [0, 0.5, 9.75, 9.75], + ], + null, + ]); + expect(opList.lastChunk).toEqual(true); + + await loadingTask.destroy(); + }); }); describe("PDFWorker", function () {