Inline the isDict
, isRef
, and isStream
checks in the src/core/xref.js
file
This commit is contained in:
parent
680e0efb9d
commit
a669fce762
@ -21,15 +21,7 @@ import {
|
|||||||
InvalidPDFException,
|
InvalidPDFException,
|
||||||
warn,
|
warn,
|
||||||
} from "../shared/util.js";
|
} from "../shared/util.js";
|
||||||
import {
|
import { Cmd, Dict, isCmd, Ref } from "./primitives.js";
|
||||||
Cmd,
|
|
||||||
Dict,
|
|
||||||
isCmd,
|
|
||||||
isDict,
|
|
||||||
isRef,
|
|
||||||
isStream,
|
|
||||||
Ref,
|
|
||||||
} from "./primitives.js";
|
|
||||||
import {
|
import {
|
||||||
DocStats,
|
DocStats,
|
||||||
MissingDataException,
|
MissingDataException,
|
||||||
@ -38,6 +30,7 @@ import {
|
|||||||
XRefParseException,
|
XRefParseException,
|
||||||
} from "./core_utils.js";
|
} from "./core_utils.js";
|
||||||
import { Lexer, Parser } from "./parser.js";
|
import { Lexer, Parser } from "./parser.js";
|
||||||
|
import { BaseStream } from "./base_stream.js";
|
||||||
import { CipherTransformFactory } from "./crypto.js";
|
import { CipherTransformFactory } from "./crypto.js";
|
||||||
|
|
||||||
class XRef {
|
class XRef {
|
||||||
@ -88,7 +81,7 @@ class XRef {
|
|||||||
}
|
}
|
||||||
warn(`XRef.parse - Invalid "Encrypt" reference: "${ex}".`);
|
warn(`XRef.parse - Invalid "Encrypt" reference: "${ex}".`);
|
||||||
}
|
}
|
||||||
if (isDict(encrypt)) {
|
if (encrypt instanceof Dict) {
|
||||||
const ids = trailerDict.get("ID");
|
const ids = trailerDict.get("ID");
|
||||||
const fileId = ids && ids.length ? ids[0] : "";
|
const fileId = ids && ids.length ? ids[0] : "";
|
||||||
// The 'Encrypt' dictionary itself should not be encrypted, and by
|
// The 'Encrypt' dictionary itself should not be encrypted, and by
|
||||||
@ -113,7 +106,7 @@ class XRef {
|
|||||||
}
|
}
|
||||||
warn(`XRef.parse - Invalid "Root" reference: "${ex}".`);
|
warn(`XRef.parse - Invalid "Root" reference: "${ex}".`);
|
||||||
}
|
}
|
||||||
if (isDict(root) && root.has("Pages")) {
|
if (root instanceof Dict && root.has("Pages")) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
} else {
|
} else {
|
||||||
if (!recoveryMode) {
|
if (!recoveryMode) {
|
||||||
@ -155,10 +148,10 @@ class XRef {
|
|||||||
let dict = parser.getObj();
|
let dict = parser.getObj();
|
||||||
|
|
||||||
// The pdflib PDF generator can generate a nested trailer dictionary
|
// The pdflib PDF generator can generate a nested trailer dictionary
|
||||||
if (!isDict(dict) && dict.dict) {
|
if (!(dict instanceof Dict) && dict.dict) {
|
||||||
dict = dict.dict;
|
dict = dict.dict;
|
||||||
}
|
}
|
||||||
if (!isDict(dict)) {
|
if (!(dict instanceof Dict)) {
|
||||||
throw new FormatError(
|
throw new FormatError(
|
||||||
"Invalid XRef table: could not parse trailer dictionary"
|
"Invalid XRef table: could not parse trailer dictionary"
|
||||||
);
|
);
|
||||||
@ -564,7 +557,7 @@ class XRef {
|
|||||||
}
|
}
|
||||||
// read the trailer dictionary
|
// read the trailer dictionary
|
||||||
const dict = parser.getObj();
|
const dict = parser.getObj();
|
||||||
if (!isDict(dict)) {
|
if (!(dict instanceof Dict)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Do some basic validation of the trailer/root dictionary candidate.
|
// Do some basic validation of the trailer/root dictionary candidate.
|
||||||
@ -656,7 +649,7 @@ class XRef {
|
|||||||
if (
|
if (
|
||||||
!Number.isInteger(parser.getObj()) ||
|
!Number.isInteger(parser.getObj()) ||
|
||||||
!isCmd(parser.getObj(), "obj") ||
|
!isCmd(parser.getObj(), "obj") ||
|
||||||
!isStream((obj = parser.getObj()))
|
!((obj = parser.getObj()) instanceof BaseStream)
|
||||||
) {
|
) {
|
||||||
throw new FormatError("Invalid XRef stream");
|
throw new FormatError("Invalid XRef stream");
|
||||||
}
|
}
|
||||||
@ -675,7 +668,7 @@ class XRef {
|
|||||||
obj = dict.get("Prev");
|
obj = dict.get("Prev");
|
||||||
if (Number.isInteger(obj)) {
|
if (Number.isInteger(obj)) {
|
||||||
this.startXRefQueue.push(obj);
|
this.startXRefQueue.push(obj);
|
||||||
} else if (isRef(obj)) {
|
} else if (obj instanceof Ref) {
|
||||||
// The spec says Prev must not be a reference, i.e. "/Prev NNN"
|
// The spec says Prev must not be a reference, i.e. "/Prev NNN"
|
||||||
// This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
|
// This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
|
||||||
this.startXRefQueue.push(obj.num);
|
this.startXRefQueue.push(obj.num);
|
||||||
@ -746,9 +739,9 @@ class XRef {
|
|||||||
} else {
|
} else {
|
||||||
xrefEntry = this.fetchCompressed(ref, xrefEntry, suppressEncryption);
|
xrefEntry = this.fetchCompressed(ref, xrefEntry, suppressEncryption);
|
||||||
}
|
}
|
||||||
if (isDict(xrefEntry)) {
|
if (xrefEntry instanceof Dict) {
|
||||||
xrefEntry.objId = ref.toString();
|
xrefEntry.objId = ref.toString();
|
||||||
} else if (isStream(xrefEntry)) {
|
} else if (xrefEntry instanceof BaseStream) {
|
||||||
xrefEntry.dict.objId = ref.toString();
|
xrefEntry.dict.objId = ref.toString();
|
||||||
}
|
}
|
||||||
return xrefEntry;
|
return xrefEntry;
|
||||||
@ -790,7 +783,7 @@ class XRef {
|
|||||||
} else {
|
} else {
|
||||||
xrefEntry = parser.getObj();
|
xrefEntry = parser.getObj();
|
||||||
}
|
}
|
||||||
if (!isStream(xrefEntry)) {
|
if (!(xrefEntry instanceof BaseStream)) {
|
||||||
if (
|
if (
|
||||||
typeof PDFJSDev === "undefined" ||
|
typeof PDFJSDev === "undefined" ||
|
||||||
PDFJSDev.test("!PRODUCTION || TESTING")
|
PDFJSDev.test("!PRODUCTION || TESTING")
|
||||||
@ -808,7 +801,7 @@ class XRef {
|
|||||||
fetchCompressed(ref, xrefEntry, suppressEncryption = false) {
|
fetchCompressed(ref, xrefEntry, suppressEncryption = false) {
|
||||||
const tableOffset = xrefEntry.offset;
|
const tableOffset = xrefEntry.offset;
|
||||||
const stream = this.fetch(Ref.get(tableOffset, 0));
|
const stream = this.fetch(Ref.get(tableOffset, 0));
|
||||||
if (!isStream(stream)) {
|
if (!(stream instanceof BaseStream)) {
|
||||||
throw new FormatError("bad ObjStm stream");
|
throw new FormatError("bad ObjStm stream");
|
||||||
}
|
}
|
||||||
const first = stream.dict.get("First");
|
const first = stream.dict.get("First");
|
||||||
@ -859,7 +852,7 @@ class XRef {
|
|||||||
|
|
||||||
const obj = parser.getObj();
|
const obj = parser.getObj();
|
||||||
entries[i] = obj;
|
entries[i] = obj;
|
||||||
if (isStream(obj)) {
|
if (obj instanceof BaseStream) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const num = nums[i],
|
const num = nums[i],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user