{"record":{"id":"73439716eb26c99c","repo":"mozilla/pdf.js","slug":"duplicate-entry-in-this-type-tree","errorCode":null,"errorMessage":"Duplicate entry in \"${this._type}\" tree.","messagePattern":"Duplicate entry in \"(.+?)\" tree\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"warning","filePath":"src/core/name_number_tree.js","lineNumber":62,"sourceCode":"    const processed = new RefSet();\n    if (this.root instanceof Ref) {\n      processed.put(this.root);\n    }\n    const queue = [this.root];\n    for (const node of queue) {\n      const obj = xref.fetchIfRef(node);\n      if (!(obj instanceof Dict)) {\n        continue;\n      }\n      if (obj.has(\"Kids\")) {\n        const kids = obj.get(\"Kids\");\n        if (!Array.isArray(kids)) {\n          continue;\n        }\n        for (const kid of kids) {\n          if (kid instanceof Ref) {\n            if (processed.has(kid)) {\n              throw new FormatError(`Duplicate entry in \"${this._type}\" tree.`);\n            }\n            processed.put(kid);\n          }\n          queue.push(kid);\n        }\n        continue;\n      }\n      const entries = obj.get(this._type);\n      if (!Array.isArray(entries)) {\n        continue;\n      }\n      for (let i = 0, ii = entries.length; i < ii; i += 2) {\n        map.set(\n          isRaw ? entries[i] : xref.fetchIfRef(entries[i]),\n          isRaw ? entries[i + 1] : xref.fetchIfRef(entries[i + 1])\n        );\n      }\n    }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/name_number_tree.js#L44-L80","documentation":"Thrown as a FormatError by NameOrNumberTree.getAll() while traversing Kids. A RefSet tracks visited kid references; if the same Ref appears twice, a cycle/duplicate is detected and the error fires. This prevents infinite loops from malformed PDF name/number trees with circular Kids references.","triggerScenarios":"getAll() iterates tree nodes; for each node with Kids, each kid that is a Ref is checked against the processed RefSet. A second occurrence of the same Ref triggers the throw. The _type in the message is 'Names' or 'Nums' depending on the tree kind.","commonSituations":"A malformed PDF where a NameTree or NumberTree (used for embedded files, JavaScript, destinations, page labels, etc.) has a Kids array pointing to the same child object twice, or a genuine cycle. Produced by buggy PDF generators or by manual/corrupt editing.","solutions":["Repair the PDF with a tool like qpdf --fix or Ghostscript to normalize the tree structure.","If generating PDFs, ensure Kids references are unique and acyclic.","If you cannot fix the source, wrap the PDF.js API call (e.g. getAttachments, getPageLabels) in a try/catch on FormatError."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const entries = nameTree.getAll();\n} catch (e) {\n  if (e.name === 'FormatError' && /Duplicate entry/.test(e.message)) { entries = new Map(); }\n  else throw e;\n}","preventionTips":["Repair malformed PDFs with qpdf --fix or Ghostscript before processing.","When generating PDFs, ensure NameTree/NumberTree Kids references are unique and acyclic.","Wrap tree-access API calls (getAttachments, getPageLabels, getOutline) in try/catch on FormatError."],"tags":["pdf","name-tree","number-tree","corrupt-data","structure"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}