{"record":{"id":"403471b0f9e5c163","repo":"mozilla/pdf.js","slug":"page-count-in-top-level-pages-dictionary-is-not-an","errorCode":null,"errorMessage":"Page count in top-level pages dictionary is not an integer.","messagePattern":"Page count in top-level pages dictionary is not an integer\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"critical","filePath":"src/core/catalog.js","lineNumber":753,"sourceCode":"      on: parseOnOff(config.get(\"ON\")),\n      off: parseOnOff(config.get(\"OFF\")),\n      order: parseOrder(config.get(\"Order\")),\n      groups: [...groupRefCache],\n    };\n  }\n\n  setActualNumPages(num = null) {\n    this.#actualNumPages = num;\n  }\n\n  get hasActualNumPages() {\n    return this.#actualNumPages !== null;\n  }\n\n  get _pagesCount() {\n    const obj = this.toplevelPagesDict.get(\"Count\");\n    if (!Number.isInteger(obj)) {\n      throw new FormatError(\n        \"Page count in top-level pages dictionary is not an integer.\"\n      );\n    }\n    return shadow(this, \"_pagesCount\", obj);\n  }\n\n  get numPages() {\n    return this.#actualNumPages ?? this._pagesCount;\n  }\n\n  get destinations() {\n    const dests = new Map();\n\n    for (const obj of this.#readDests()) {\n      if (obj instanceof NameTree) {\n        for (const [key, value] of obj.getAll()) {\n          const dest = fetchDest(value);\n          if (dest) {","sourceCodeStart":735,"sourceCodeEnd":771,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/catalog.js#L735-L771","documentation":"Thrown by the _pagesCount getter (catalog.js:753) when the /Pages root dictionary's /Count value is not an integer. /Count must be an integer giving the total number of pages; a float, string, null, or name makes the page count unknowable.","triggerScenarios":"this.toplevelPagesDict.get('Count') returns a non-integer (e.g., 3.0 stored as a real, a string, or undefined/null). Reached via the numPages getter (numPages falls back to _pagesCount when no actualNumPages is set), which is used pervasively during rendering and indexing.","commonSituations":"A PDF producer that wrote /Count as a floating-point or wrong type; a corrupt object where /Count was overwritten; a page tree root missing /Count; an edited PDF with a malformed count.","solutions":["Repair with 'qpdf --linearize' or 'mutool clean' to normalise /Count to an integer.","If you control the producer, ensure /Count is emitted as a PDF integer token.","Validate the PDF with 'qpdf --check' to surface the malformed /Count before loading.","Fall back to loading with a repaired copy when the original is rejected."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Cannot read /Count cheaply pre-load; rely on repair for known-bad producers.\n// If you generate PDFs, write /Count as an integer.\n// For inputs, run: qpdf --check in.pdf  (reports malformed /Count)","typeGuard":null,"tryCatchPattern":"try {\n  const pdf = await getDocument({ data: arrayBuffer }).promise;\n  const n = pdf.numPages; // access triggers _pagesCount\n} catch (err) {\n  if (/Page count.*not an integer/i.test(err?.message)) {\n    throw new Error('PDF /Count is malformed; repair with qpdf/mutool.', { cause: err });\n  }\n  throw err;\n}","preventionTips":["Repair malformed /Count with qpdf/mutool before loading.","When producing PDFs, emit /Count as a PDF integer token.","Run 'qpdf --check' to detect the bad count early.","Reject or quarantine files that fail structural checks."],"tags":["pdf-structure","catalog","pages-tree","corrupt-pdf","validation"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}