mozilla/pdf.js · error · FormatError
invalid object offset in the ObjStm stream: ${offset}
Error message
invalid object offset in the ObjStm stream: ${offset} What it means
A FormatError raised in the same ObjStm header-parsing loop as 223, but for the offset member of each (objectNumber, offset) pair: the offset read from the stream is not an integer. Without valid integer offsets, pdf.js cannot locate each compressed object inside the stream. The offending value is shown in the message.
Source
Thrown at src/core/xref.js:985
}
let parser = new Parser({
lexer: new Lexer(stream),
xref: this,
allowStreams: true,
});
const nums = new Array(n);
const offsets = new Array(n);
// read the object numbers to populate cache
for (let i = 0; i < n; ++i) {
const num = parser.getObj();
if (!Number.isInteger(num)) {
throw new FormatError(
`invalid object number in the ObjStm stream: ${num}`
);
}
const offset = parser.getObj();
if (!Number.isInteger(offset)) {
throw new FormatError(
`invalid object offset in the ObjStm stream: ${offset}`
);
}
nums[i] = num;
// The entry in the xref table is the object number followed by the index.
// So if index (gen number) is not the same as the index (i), we fix it
// (fixes bug 1978317).
const entry = this.getEntry(num);
if (entry?.offset === tableOffset && entry.gen !== i) {
entry.gen = i;
}
offsets[i] = offset;
}
const start = (stream.start || 0) + first;
const entries = new Array(n);View on GitHub (pinned to 5903d58d58)
Solutions
- Ensure the full file was downloaded (compare to Content-Length / re-fetch).
- Rebuild object streams with qpdf --object-streams=generate or mutool clean.
- Catch FormatError per page and degrade gracefully.
- Re-export from the source application if you own it.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await doc.getPage(n);
} catch (e) {
if (e instanceof pdfjsLib.FormatError) continue;
throw e;
} Prevention
- Pre-validate downloads against expected size/hash.
- Repair with qpdf/mutool before processing.
- Isolate per-page errors so one corrupt object stream does not fail everything.
When it happens
Trigger: Same family as 223: truncated, reordered, or decrypted-garbage ObjStm content where the offset token fails to parse as an integer.
Common situations: Truncated downloads, faulty PDF generators, deflate corruption, post-decryption byte misalignment.
Related errors
- invalid object number in the ObjStm stream: ${num}
- bad ObjStm stream
- invalid first and n parameters for ObjStm stream
- Invalid offset in the ObjStm stream.
- Bad FCHECK in flate stream: ${cmf}, ${flg}
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/348fc71bf1324da4.
Report an issue: GitHub.