{"record":{"id":"e912f848dc12fe1d","repo":"mozilla/pdf.js","slug":"invalid-entry-in-differences-array-data","errorCode":null,"errorMessage":"Invalid entry in 'Differences' array: ${data}","messagePattern":"Invalid entry in 'Differences' array: (.+?)","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/evaluator.js","lineNumber":3665,"sourceCode":"    let encoding;\n    if (dict.has(\"Encoding\")) {\n      encoding = dict.get(\"Encoding\");\n      if (encoding instanceof Dict) {\n        baseEncodingName = encoding.get(\"BaseEncoding\");\n        baseEncodingName =\n          baseEncodingName instanceof Name ? baseEncodingName.name : null;\n        // Load the differences between the base and original\n        if (encoding.has(\"Differences\")) {\n          const diffEncoding = encoding.get(\"Differences\");\n          let index = 0;\n          for (const entry of diffEncoding) {\n            const data = xref.fetchIfRef(entry);\n            if (typeof data === \"number\") {\n              index = data;\n            } else if (data instanceof Name) {\n              differences[index++] = data.name;\n            } else {\n              throw new FormatError(\n                `Invalid entry in 'Differences' array: ${data}`\n              );\n            }\n          }\n        }\n      } else if (encoding instanceof Name) {\n        baseEncodingName = encoding.name;\n      } else {\n        const msg = \"Encoding is not a Name nor a Dict\";\n\n        if (!this.options.ignoreErrors) {\n          throw new FormatError(msg);\n        }\n        warn(msg);\n      }\n      // According to table 114 if the encoding is a named encoding it must be\n      // one of these predefined encodings.\n      if (","sourceCodeStart":3647,"sourceCodeEnd":3683,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/evaluator.js#L3647-L3683","documentation":"Thrown while parsing a font's /Encoding /Differences array when an entry is neither a number (used to set the current code index) nor a Name (a glyph name like /A). The PDF spec defines the Differences array as an alternating sequence of integers and name operands; any other type is illegal. The error message interpolates the offending value to aid diagnosis.","triggerScenarios":"A font dictionary whose /Encoding >> /Differences array contains a string, boolean, dictionary, null, or other non-spec type at a position where a code-point integer or glyph Name is expected. Fires during font loading (PartialEvaluator.translateFont) on any page that uses the font.","commonSituations":"Hand-edited PDFs, buggy font subsetting tools, or PDFs that survived a corrupt linearization. Especially common in documents produced by legacy desktop-publishing pipelines or office-software PDF export plugins with encoding bugs.","solutions":["Repair the PDF: run it through qpdf --check then qpdf --linearize, or Ghostscript (gs -sDEVICE=pdfwrite) to normalize the encoding.","If you generate the PDF, audit your Differences-array writer to emit only integers and /Names.","Wrap font-dependent operations (render, getTextContent) per-page in try/catch and degrade gracefully.","Open in Acrobat; if it warns about the font, the encoding is definitively corrupt and must be repaired at the source."],"exampleFix":"// before\nawait page.render({ canvasContext, viewport }); // throws on bad Encoding\n\n// after\ntry {\n  await page.render({ canvasContext, viewport });\n} catch (e) {\n  if (e.name === 'FormatError') {\n    console.warn('Font encoding corrupt, rendering text may be incomplete');\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await page.render({ canvasContext, viewport });\n} catch (e) {\n  if (e.name === 'FormatError' && /Invalid entry in 'Differences'/.test(e.message)) {\n    console.warn('Font encoding corrupt on this page; text may be wrong');\n  } else throw e;\n}","preventionTips":["Normalize PDFs through Ghostscript (gs -sDEVICE=pdfwrite) to rebuild encoding dictionaries.","When authoring font /Encoding /Differences, only emit integers and Name operands.","Run qpdf --check as a pre-screening step in batch processing pipelines."],"tags":["pdf","font","encoding","differences","format-error"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}