mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Prevent circular references in the /Pages tree
This commit is contained in:
parent
e2b30e9e9c
commit
3c7b7be100
7 changed files with 155 additions and 8 deletions
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -117,6 +117,7 @@
|
|||
!bug1132849.pdf
|
||||
!issue6894.pdf
|
||||
!issue5804.pdf
|
||||
!Pages-tree-refs.pdf
|
||||
!ShowText-ShadingPattern.pdf
|
||||
!complex_ttf_font.pdf
|
||||
!issue3694_reduced.pdf
|
||||
|
|
84
test/pdfs/Pages-tree-refs.pdf
Normal file
84
test/pdfs/Pages-tree-refs.pdf
Normal file
|
@ -0,0 +1,84 @@
|
|||
%PDF-1.7
|
||||
|
||||
1 0 obj
|
||||
<< /Type /Catalog
|
||||
/Pages 2 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
2 0 obj
|
||||
<< /Type /Pages
|
||||
/Kids [6 0 R 3 0 R]
|
||||
/Count 2
|
||||
/MediaBox [0 0 595 842]
|
||||
>>
|
||||
endobj
|
||||
|
||||
3 0 obj
|
||||
<< /Type /Pages
|
||||
/Kids [4 0 R]
|
||||
/Count 1
|
||||
/MediaBox [0 0 595 842]
|
||||
>>
|
||||
endobj
|
||||
|
||||
4 0 obj
|
||||
<< /Type /Pages
|
||||
/Kids [5 0 R]
|
||||
/Count 1
|
||||
/MediaBox [0 0 595 842]
|
||||
>>
|
||||
endobj
|
||||
|
||||
5 0 obj
|
||||
<< /Type /Pages
|
||||
/Kids [3 0 R]
|
||||
/Count 1
|
||||
/MediaBox [0 0 595 842]
|
||||
>>
|
||||
endobj
|
||||
|
||||
6 0 obj
|
||||
<< /Type /Page
|
||||
/Parent 2 0 R
|
||||
/Resources
|
||||
<< /Font
|
||||
<< /F1
|
||||
<< /Type /Font
|
||||
/Subtype /Type1
|
||||
/BaseFont /Courier
|
||||
>>
|
||||
>>
|
||||
>>
|
||||
/Contents [7 0 R]
|
||||
>>
|
||||
endobj
|
||||
|
||||
7 0 obj
|
||||
<< /Length 69 >>
|
||||
stream
|
||||
BT
|
||||
/F1 22 Tf
|
||||
30 800 Td
|
||||
(Testcase: 'Pages loop') Tj
|
||||
ET
|
||||
endstream
|
||||
endobj
|
||||
|
||||
xref
|
||||
0 8
|
||||
0000000000 65535 f
|
||||
0000000010 00000 n
|
||||
0000000069 00000 n
|
||||
0000000176 00000 n
|
||||
0000000277 00000 n
|
||||
0000000378 00000 n
|
||||
0000000479 00000 n
|
||||
0000000744 00000 n
|
||||
trailer
|
||||
<< /Root 1 0 R
|
||||
/Size 8
|
||||
>>
|
||||
startxref
|
||||
866
|
||||
%%EOF
|
|
@ -546,6 +546,43 @@ describe("api", function() {
|
|||
})
|
||||
.catch(done.fail);
|
||||
});
|
||||
|
||||
it("gets page, from /Pages tree with circular reference", function(done) {
|
||||
const loadingTask = getDocument(
|
||||
buildGetDocumentParams("Pages-tree-refs.pdf")
|
||||
);
|
||||
|
||||
const page1 = loadingTask.promise.then(function(pdfDoc) {
|
||||
return pdfDoc.getPage(1).then(
|
||||
function(pdfPage) {
|
||||
expect(pdfPage instanceof PDFPageProxy).toEqual(true);
|
||||
expect(pdfPage.ref).toEqual({ num: 6, gen: 0 });
|
||||
},
|
||||
function(reason) {
|
||||
throw new Error("shall not fail for valid page");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const page2 = loadingTask.promise.then(function(pdfDoc) {
|
||||
return pdfDoc.getPage(2).then(
|
||||
function(pdfPage) {
|
||||
throw new Error("shall fail for invalid page");
|
||||
},
|
||||
function(reason) {
|
||||
expect(reason instanceof Error).toEqual(true);
|
||||
expect(reason.message).toEqual(
|
||||
"Pages tree contains circular reference."
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Promise.all([page1, page2]).then(function() {
|
||||
loadingTask.destroy().then(done);
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it("gets page index", function(done) {
|
||||
// reference to second page
|
||||
var ref = { num: 17, gen: 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue