mozilla/pdf.js · error · FormatError

Invalid dictionary name "${name}"

Error message

Invalid dictionary name "${name}"

What it means

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.

Source

Thrown at src/core/cff_parser.js:1269

    // Ignore invalid values (fixes bug1068432.pdf and bug1308536.pdf).
    for (const val of value) {
      if (isNaN(val)) {
        warn(`Invalid CFFDict value: "${value}" for key "${key}".`);
        return true;
      }
    }
    const type = this.types[key];
    // remove the array wrapping these types of values
    if (type === "num" || type === "sid" || type === "offset") {
      value = value[0];
    }
    this.values[key] = value;
    return true;
  }

  setByName(name, value) {
    if (!(name in this.nameToKeyMap)) {
      throw new FormatError(`Invalid dictionary name "${name}"`);
    }
    this.values[this.nameToKeyMap[name]] = value;
  }

  hasName(name) {
    return this.nameToKeyMap[name] in this.values;
  }

  getByName(name) {
    if (!(name in this.nameToKeyMap)) {
      throw new FormatError(`Invalid dictionary name ${name}"`);
    }
    const key = this.nameToKeyMap[name];
    if (!(key in this.values)) {
      return this.defaults[key];
    }
    return this.values[key];
  }

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Ensure the name is registered in the relevant CFF*DictLayout table (e.g., CFFTopDictLayout) before calling setByName.
  2. Check for typos in the operator name string.
  3. If extending pdf.js, add the [opcode, name, type, default] entry so nameToKeyMap includes it.

Example fix

// before
dict.setByName('MyCustomOp', value); // throws if unregistered

// after
// Register in the layout table first, e.g. CFFPrivateDictLayout:
//   [19, 'MyCustomOp', 'num', 0],
dict.setByName('MyCustomOp', value); // now valid
Defensive patterns

Strategy: validation

Validate before calling

// Only call setByName with names registered in the dict's layout.
function safeSetByName(dict, name, value) {
  if (!(name in dict.nameToKeyMap)) {
    throw new Error(`Refusing setByName: '${name}' is not registered`);
  }
  dict.setByName(name, value);
}

Type guard

// Guard for internal CFF dict name validity.
function isValidCFFDictName(dict, name) {
  return typeof name === 'string' && name in dict.nameToKeyMap;
}

Try / catch

try {
  dict.setByName(name, value);
} catch (e) {
  // Name not registered; this is an internal API misuse, not bad input.
  throw new Error(`CFF dict name '${name}' is not in the layout table`);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/a4f301d3c31491c0. Report an issue: GitHub.