{"record":{"id":"a4f301d3c31491c0","repo":"mozilla/pdf.js","slug":"invalid-dictionary-name-name","errorCode":null,"errorMessage":"Invalid dictionary name \"${name}\"","messagePattern":"Invalid dictionary name \"(.+?)\"","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/cff_parser.js","lineNumber":1269,"sourceCode":"    // Ignore invalid values (fixes bug1068432.pdf and bug1308536.pdf).\n    for (const val of value) {\n      if (isNaN(val)) {\n        warn(`Invalid CFFDict value: \"${value}\" for key \"${key}\".`);\n        return true;\n      }\n    }\n    const type = this.types[key];\n    // remove the array wrapping these types of values\n    if (type === \"num\" || type === \"sid\" || type === \"offset\") {\n      value = value[0];\n    }\n    this.values[key] = value;\n    return true;\n  }\n\n  setByName(name, value) {\n    if (!(name in this.nameToKeyMap)) {\n      throw new FormatError(`Invalid dictionary name \"${name}\"`);\n    }\n    this.values[this.nameToKeyMap[name]] = value;\n  }\n\n  hasName(name) {\n    return this.nameToKeyMap[name] in this.values;\n  }\n\n  getByName(name) {\n    if (!(name in this.nameToKeyMap)) {\n      throw new FormatError(`Invalid dictionary name ${name}\"`);\n    }\n    const key = this.nameToKeyMap[name];\n    if (!(key in this.values)) {\n      return this.defaults[key];\n    }\n    return this.values[key];\n  }","sourceCodeStart":1251,"sourceCodeEnd":1287,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/cff_parser.js#L1251-L1287","documentation":"Thrown by CFFDict.setByName when called with a name not registered in that dictionary's nameToKeyMap. Each CFF dictionary class (Top/Private/Font) only knows a fixed set of operator names from its layout table; passing an unrecognized name is an internal API misuse.","triggerScenarios":"Internal code (or a fork/extension) calls `dict.setByName('SomeName', value)` where 'SomeName' is not in the dict's layout table. This is not reachable from normal PDF input — it indicates a programming error in code building or repairing CFF dictionaries.","commonSituations":"A pdf.js patch that adds a new operator name but forgets to register it in the layout table; a fork that passes made-up names; typos in operator-name strings within internal font-repair logic.","solutions":["Ensure the name is registered in the relevant CFF*DictLayout table (e.g., CFFTopDictLayout) before calling setByName.","Check for typos in the operator name string.","If extending pdf.js, add the [opcode, name, type, default] entry so nameToKeyMap includes it."],"exampleFix":"// before\ndict.setByName('MyCustomOp', value); // throws if unregistered\n\n// after\n// Register in the layout table first, e.g. CFFPrivateDictLayout:\n//   [19, 'MyCustomOp', 'num', 0],\ndict.setByName('MyCustomOp', value); // now valid","handlingStrategy":"validation","validationCode":"// Only call setByName with names registered in the dict's layout.\nfunction safeSetByName(dict, name, value) {\n  if (!(name in dict.nameToKeyMap)) {\n    throw new Error(`Refusing setByName: '${name}' is not registered`);\n  }\n  dict.setByName(name, value);\n}","typeGuard":"// Guard for internal CFF dict name validity.\nfunction isValidCFFDictName(dict, name) {\n  return typeof name === 'string' && name in dict.nameToKeyMap;\n}","tryCatchPattern":"try {\n  dict.setByName(name, value);\n} catch (e) {\n  // Name not registered; this is an internal API misuse, not bad input.\n  throw new Error(`CFF dict name '${name}' is not in the layout table`);\n}","preventionTips":["Register every operator name in the relevant CFF*DictLayout table before use.","Guard setByName with a nameToKeyMap membership check.","Treat this error as a code bug, not a data issue."],"tags":["font","cff","cff-dict","internal-api","invariant"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}