Skip to content

Commit

Permalink
Merge pull request #15152 from Snuffleupagus/validate-Resources
Browse files Browse the repository at this point in the history
Ensure that the /Resources-entry is actually a dictionary (issue 15150)
  • Loading branch information
Snuffleupagus authored Jul 8, 2022
2 parents efbd429 + c2f7942 commit 4b493c2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added test/pdfs/issue15150.pdf
Binary file not shown.
32 changes: 32 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 4b493c2

Please sign in to comment.