Skip to content
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
16 changes: 16 additions & 0 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,22 @@ class Catalog {
}
}
if (!Array.isArray(kids)) {
// Prevent errors in corrupt PDF documents that violate the
// specification by *inlining* Page dicts (fixes issue21436.pdf).
let type = currentNode.getRaw("Type");
if (type instanceof Ref) {
try {
type = await xref.fetchAsync(type);
} catch (ex) {
addPageError(ex);
break;
}
}
if (isName(type, "Page") || !currentNode.has("Kids")) {
addPageDict(currentNode, null);
break;
}

addPageError(
new FormatError("Page dictionary kids object is not an array.")
);
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@
!issue_cff_unsigned_bbox.pdf
!90ms_rksj_h_sample.pdf
!issue21346.pdf
!issue21436.pdf
!cidfont_cmap_overflow.pdf
!jbig2_file_header.pdf
!text_field_own_canvas_calc.pdf
Binary file added test/pdfs/issue21436.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2802,6 +2802,13 @@
"link": true,
"type": "eq"
},
{
"id": "issue21436",
"file": "pdfs/issue21436.pdf",
"md5": "93c4292a52db8a37eefd651cb677d2a9",
"rounds": 1,
"type": "eq"
},
{
"id": "txt2pdf",
"file": "pdfs/txt2pdf.pdf",
Expand Down
36 changes: 36 additions & 0 deletions test/unit/api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,42 @@ describe("api", function () {
]);
});

it("creates pdf doc from PDF files, with /Pages tree without /Kids array", async function () {
const loadingTask1 = getDocument(buildGetDocumentParams("issue9540.pdf"));
const loadingTask2 = getDocument(
buildGetDocumentParams("issue21436.pdf")
);

expect(loadingTask1).toBeInstanceOf(PDFDocumentLoadingTask);
expect(loadingTask2).toBeInstanceOf(PDFDocumentLoadingTask);

const pdfDocument1 = await loadingTask1.promise;
const pdfDocument2 = await loadingTask2.promise;

expect(pdfDocument1.numPages).toEqual(1);
expect(pdfDocument2.numPages).toEqual(1);

const pageA = await pdfDocument1.getPage(1);
expect(pageA).toBeInstanceOf(PDFPageProxy);

const opListA = await pageA.getOperatorList();
expect(opListA.fnArray.length).toEqual(19);
expect(opListA.argsArray.length).toEqual(19);
expect(opListA.lastChunk).toEqual(true);
expect(opListA.separateAnnots).toEqual(null);

const pageB = await pdfDocument2.getPage(1);
expect(pageB).toBeInstanceOf(PDFPageProxy);

const opListB = await pageB.getOperatorList();
expect(opListB.fnArray.length).toEqual(1);
expect(opListB.argsArray.length).toEqual(1);
expect(opListB.lastChunk).toEqual(true);
expect(opListB.separateAnnots).toEqual(null);

await Promise.all([loadingTask1.destroy(), loadingTask2.destroy()]);
});

it("creates pdf doc from PDF files, with circular references", async function () {
const loadingTask1 = getDocument(
buildGetDocumentParams("poppler-91414-0-53.pdf")
Expand Down
Loading