mozilla/pdf.js · error · FormatError

Malformed CMap: expected int.

Error message

Malformed CMap: expected int.

What it means

Thrown by the expectInt helper while parsing a CMap when the lexer yields a non-integer at a position that requires an integer token (for example the destination of a cidrange/cidchar entry). Indicates the CMap stream is structurally malformed.

Source

Thrown at src/core/cmap.js:458

}

function strToInt(str) {
  let a = 0;
  for (let i = 0; i < str.length; i++) {
    a = (a << 8) | str.charCodeAt(i);
  }
  return a >>> 0;
}

function expectString(obj) {
  if (typeof obj !== "string") {
    throw new FormatError("Malformed CMap: expected string.");
  }
}

function expectInt(obj) {
  if (!Number.isInteger(obj)) {
    throw new FormatError("Malformed CMap: expected int.");
  }
}

function parseBfChar(cMap, lexer) {
  while (true) {
    let obj = lexer.getObj();
    if (obj === EOF) {
      break;
    }
    if (isCmd(obj, "endbfchar")) {
      return;
    }
    expectString(obj);
    const src = strToInt(obj);
    obj = lexer.getObj();
    // TODO are /dstName used?
    expectString(obj);
    const dst = obj;

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Repair or regenerate the PDF.
  2. Update pdf.js.
  3. Catch FormatError and continue without that CMap (degrades CID text extraction).
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await loadingTask.promise;
} catch (e) {
  if (e instanceof FormatError && /expected int/.test(e.message)) {
    console.warn('Malformed CMap (expected int), CID mapping may degrade', e);
  } else throw e;
}

Prevention

When it happens

Trigger: Parsing a CMap where a token that must be an integer (CID destination, etc.) is a string, Name, Cmd, or float. Reached via parseCidChar / parseCidRange calling expectInt.

Common situations: Truncated or corrupt CID CMap; wrong stream referenced as a CMap; PDF produced by a faulty font tool.

Understand the failure class

Related errors


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