mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Fallback to finding the first "obj" occurrence, when the trailer-dictionary is incomplete (issue 15590)
Note that the "trailer"-case is already a fallback, since normally we're able to use the "xref"-operator even in corrupt documents. However, when a "trailer"-operator is found we still expect "startxref" to exist and be usable in order to advance the stream position. When that's not the case, as happens in the referenced issue, we use a simple fallback to find the first "obj" occurrence instead. This *partially* fixes issue 15590, since without this patch we fail to find any objects at all during `XRef.indexObjects`. However, note that the PDF document is still corrupt and won't render since there's no actual /Pages-dictionary and the /Root-entry simply points to the /OpenAction-dictionary instead.
This commit is contained in:
parent
2ae90f9615
commit
2516ffa78e
4 changed files with 75 additions and 2 deletions
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -351,6 +351,7 @@
|
|||
!issue9534_reduced.pdf
|
||||
!attachment.pdf
|
||||
!basicapi.pdf
|
||||
!issue15590.pdf
|
||||
!issue15594_reduced.pdf
|
||||
!issue2884_reduced.pdf
|
||||
!mixedfonts.pdf
|
||||
|
|
23
test/pdfs/issue15590.pdf
Normal file
23
test/pdfs/issue15590.pdf
Normal file
|
@ -0,0 +1,23 @@
|
|||
%PDF-1.7
|
||||
|
||||
trailer
|
||||
<<
|
||||
/Root 1 0 R
|
||||
>>
|
||||
|
||||
1 0 obj
|
||||
<<
|
||||
/Type /Catalog
|
||||
/Pages 2 0 R
|
||||
/OpenAction 2 0 R
|
||||
>>
|
||||
endobj
|
||||
|
||||
2 0 obj
|
||||
<<
|
||||
/S /JavaScript
|
||||
/JS(func=function(){app.alert(1)};func();)
|
||||
>>
|
||||
endobj
|
||||
|
||||
%%EOF
|
|
@ -738,6 +738,33 @@ describe("api", function () {
|
|||
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
|
||||
it("creates pdf doc from PDF file, with incomplete trailer", async function () {
|
||||
const loadingTask = getDocument(buildGetDocumentParams("issue15590.pdf"));
|
||||
expect(loadingTask instanceof PDFDocumentLoadingTask).toEqual(true);
|
||||
|
||||
const pdfDocument = await loadingTask.promise;
|
||||
expect(pdfDocument.numPages).toEqual(1);
|
||||
|
||||
const jsActions = await pdfDocument.getJSActions();
|
||||
expect(jsActions).toEqual({
|
||||
OpenAction: ["func=function(){app.alert(1)};func();"],
|
||||
});
|
||||
|
||||
try {
|
||||
await pdfDocument.getPage(1);
|
||||
|
||||
// Shouldn't get here.
|
||||
expect(false).toEqual(true);
|
||||
} catch (reason) {
|
||||
expect(reason instanceof UnknownErrorException).toEqual(true);
|
||||
expect(reason.message).toEqual(
|
||||
"Page dictionary kids object is not an array."
|
||||
);
|
||||
}
|
||||
|
||||
await loadingTask.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("PDFWorker", function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue