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

Ensure that the /Resources-entry is actually a dictionary (issue 15150) #15152

Merged
merged 1 commit into from
Jul 8, 2022
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
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