{"record":{"id":"713258b9962acf84","repo":"mozilla/pdf.js","slug":"end-of-file-inside-array","errorCode":null,"errorMessage":"End of file inside array.","messagePattern":"End of file inside array\\.","errorType":"exception","errorClass":"ParserEOFException","httpStatus":null,"severity":"error","filePath":"src/core/parser.js","lineNumber":138,"sourceCode":"   */\n  getObj(cipherTransform = null) {\n    const buf1 = this.buf1;\n    this.shift();\n\n    if (buf1 instanceof Cmd) {\n      switch (buf1.cmd) {\n        case \"BI\": // inline image\n          return this.makeInlineImage(cipherTransform);\n        case \"[\": // array\n          const array = [];\n          while (!isCmd(this.buf1, \"]\") && this.buf1 !== EOF) {\n            array.push(this.getObj(cipherTransform));\n          }\n          if (this.buf1 === EOF) {\n            if (this.recoveryMode) {\n              return array;\n            }\n            throw new ParserEOFException(\"End of file inside array.\");\n          }\n          this.shift();\n          return array;\n        case \"<<\": // dictionary or stream\n          const dict = new Dict(this.xref);\n          while (!isCmd(this.buf1, \">>\") && this.buf1 !== EOF) {\n            if (!(this.buf1 instanceof Name)) {\n              info(\"Malformed dictionary: key must be a name object\");\n              this.shift();\n              continue;\n            }\n\n            const key = this.buf1.name;\n            this.shift();\n            if (this.buf1 === EOF) {\n              break;\n            }\n            dict.set(key, this.getObj(cipherTransform));","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/parser.js#L120-L156","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await pdfjsLib.getDocument({ data }).promise;\n} catch (e) {\n  if (e.name === 'ParserEOFException') { /* truncated PDF */ }\n  else throw e;\n}","preventionTips":["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."],"tags":["pdf","parser","corrupt-data","truncation","structure"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}