mozilla/pdf.js · error · ParserEOFException
End of file inside array.
Error message
End of file inside array.
What it means
Thrown as a ParserEOFException by Parser.getObj() while collecting array elements. The loop reads objects until it sees ']' or EOF; if EOF arrives first the array is unterminated. In recoveryMode the partial array is returned instead of throwing — recovery mode is used during PDF repair.
Source
Thrown at src/core/parser.js:138
*/
getObj(cipherTransform = null) {
const buf1 = this.buf1;
this.shift();
if (buf1 instanceof Cmd) {
switch (buf1.cmd) {
case "BI": // inline image
return this.makeInlineImage(cipherTransform);
case "[": // array
const array = [];
while (!isCmd(this.buf1, "]") && this.buf1 !== EOF) {
array.push(this.getObj(cipherTransform));
}
if (this.buf1 === EOF) {
if (this.recoveryMode) {
return array;
}
throw new ParserEOFException("End of file inside array.");
}
this.shift();
return array;
case "<<": // dictionary or stream
const dict = new Dict(this.xref);
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));View on GitHub (pinned to 5903d58d58)
Solutions
- Ensure the PDF file is complete — re-download or verify file size against Content-Length.
- If using range requests (disableRange/enableRange), confirm all requested ranges were satisfied.
- For repair, PDF.js retries parsing in recoveryMode which returns the partial array; if that's insufficient, rebuild the PDF with qpdf/Ghostscript.
- Catch ParserEOFException at the document-load level to fail gracefully.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await pdfjsLib.getDocument({ data }).promise;
} catch (e) {
if (e.name === 'ParserEOFException') { /* truncated PDF */ }
else throw e;
} Prevention
- Ensure the PDF is fully downloaded (verify size against Content-Length).
- Confirm range requests are satisfied when progressive loading is enabled.
- For damaged files, let PDF.js retry in recoveryMode or rebuild with qpdf/Ghostscript.
When it happens
Trigger: getObj() handles a '[' command and loops reading objects; this.buf1 becomes EOF before ']' is found. Indicates the PDF stream was truncated mid-array or the array's closing bracket is missing/corrupted.
Common situations: A truncated PDF (download interrupted, range-request gaps), a PDF whose object stream or body was cut off, or corruption that consumed the ']'. Common with partially-written or damaged files. The parser's recoveryMode (enabled on second-chance parsing) suppresses this.
Related errors
- End of file inside dictionary.
- 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/713258b9962acf84.
Report an issue: GitHub.