mozilla/pdf.js · error · ParserEOFException
End of file inside dictionary.
Error message
End of file inside dictionary.
What it means
Thrown as a ParserEOFException by Parser.getObj() while collecting dictionary key/value pairs. The loop reads entries until '>>' or EOF; if EOF arrives first the dictionary is unterminated. As with arrays, recoveryMode returns the partial dict instead of throwing.
Source
Thrown at src/core/parser.js:162
while (!isCmd(this.buf1, ">>") && this.buf1 !== EOF) {
if (!(this.buf1 instanceof Name)) {
info("Malformed dictionary: key must be a name object");
this.shift();
continue;
}
const key = this.buf1.name;
this.shift();
if (this.buf1 === EOF) {
break;
}
dict.set(key, this.getObj(cipherTransform));
}
if (this.buf1 === EOF) {
if (this.recoveryMode) {
return dict;
}
throw new ParserEOFException("End of file inside dictionary.");
}
// Stream objects are not allowed inside content streams or
// object streams.
if (isCmd(this.buf2, "stream")) {
return this.allowStreams
? this.makeStream(dict, cipherTransform)
: dict;
}
this.shift();
return dict;
default: // simple object
return buf1;
}
}
if (Number.isInteger(buf1)) {
// indirect reference or integerView on GitHub (pinned to 5903d58d58)
Solutions
- Verify the PDF is fully downloaded (check file size, re-fetch).
- If a specific object is implicated, inspect it with qpdf --qdf to linearize and locate the truncation.
- Let PDF.js retry in recoveryMode; if it still fails, rebuild the PDF with qpdf --fix or Ghostscript.
- Catch ParserEOFException during PDFDocumentLoadingTask to present a graceful error.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await pdfjsLib.getDocument({ data }).promise;
} catch (e) {
if (e.name === 'ParserEOFException') { /* truncated dict, attempt recovery */ }
else throw e;
} Prevention
- Verify the PDF is complete and not truncated.
- Use qpdf --check or --fix to validate/repair dictionaries.
- Catch ParserEOFException at document load to degrade gracefully.
When it happens
Trigger: getObj() handles a '<<' command and loops; this.buf1 becomes EOF before '>>'. The dictionary stream was truncated or the closing '>>' is missing. Fires after the loop's EOF break when not in recoveryMode.
Common situations: Truncated PDF where an object dictionary is cut off, corruption that damaged the '>>' delimiter, or a stream whose /Length was wrong causing the parser to lose position. Very common symptom of incomplete downloads or damaged object streams.
Related errors
- End of file inside array.
- Dictionary key must be a name object
- Duplicate entry in "${this._type}" tree.
- Invalid header in flate stream: ${cmf}, ${flg}
- Parent must be a dictionary.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/2f372b0356afe9a8.
Report an issue: GitHub.