mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Subtract start offset for xrefs in recovery mode
Xref offsets are relative to the start of the PDF data, not to the start of the PDF file. This is clear if you look at the other code: - In the XRef's readXRefTable and processXRefTable methods of XRef, the offset of a xref entry is set to the bytes as given by a PDF file. These values are always relative to the start of the PDF file (%PDF-). - The XRef's readXRef method adds the start offset of the stream to Xref entry's offset: "stream.pos = startXRef + stream.start". Clearly, this line assumes that the entry offset excludes the start offset. However, when the PDF is parsed in recovery mode, the xref table is filled with entries whose offset is relative to the start of the stream rather than the PDF file. This is incorrect, and the fix is to subtract the start offset of the stream from the entry's byte offset. The manually created PDF file serves as a regression test. It is a valid PDF, except: - The integer to point to the start of the xref table and the %%EOF trailer are missing. This will activate recovery mode in PDF.js - Some junk was added before the start of the PDF file. This exposes the bad offset bug.
This commit is contained in:
parent
eb2ad11571
commit
fd29bb0c57
4 changed files with 38 additions and 3 deletions
|
@ -1081,7 +1081,7 @@ var XRef = (function XRefClosure() {
|
|||
} else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
|
||||
if (typeof this.entries[m[1]] === 'undefined') {
|
||||
this.entries[m[1]] = {
|
||||
offset: position,
|
||||
offset: position - stream.start,
|
||||
gen: m[2] | 0,
|
||||
uncompressed: true
|
||||
};
|
||||
|
@ -1094,8 +1094,8 @@ var XRef = (function XRefClosure() {
|
|||
var xrefTagOffset = skipUntil(content, 0, xrefBytes);
|
||||
if (xrefTagOffset < contentLength &&
|
||||
content[xrefTagOffset + 5] < 64) {
|
||||
xrefStms.push(position);
|
||||
this.xrefstms[position] = 1; // don't read it recursively
|
||||
xrefStms.push(position - stream.start);
|
||||
this.xrefstms[position - stream.start] = 1; // Avoid recursion
|
||||
}
|
||||
|
||||
position += contentLength;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue