{"record":{"id":"29107a194ebb7054","repo":"mozilla/pdf.js","slug":"malformed-cmap-expected-int","errorCode":null,"errorMessage":"Malformed CMap: expected int.","messagePattern":"Malformed CMap: expected int\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/cmap.js","lineNumber":458,"sourceCode":"}\n\nfunction strToInt(str) {\n  let a = 0;\n  for (let i = 0; i < str.length; i++) {\n    a = (a << 8) | str.charCodeAt(i);\n  }\n  return a >>> 0;\n}\n\nfunction expectString(obj) {\n  if (typeof obj !== \"string\") {\n    throw new FormatError(\"Malformed CMap: expected string.\");\n  }\n}\n\nfunction expectInt(obj) {\n  if (!Number.isInteger(obj)) {\n    throw new FormatError(\"Malformed CMap: expected int.\");\n  }\n}\n\nfunction parseBfChar(cMap, lexer) {\n  while (true) {\n    let obj = lexer.getObj();\n    if (obj === EOF) {\n      break;\n    }\n    if (isCmd(obj, \"endbfchar\")) {\n      return;\n    }\n    expectString(obj);\n    const src = strToInt(obj);\n    obj = lexer.getObj();\n    // TODO are /dstName used?\n    expectString(obj);\n    const dst = obj;","sourceCodeStart":440,"sourceCodeEnd":476,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/cmap.js#L440-L476","documentation":"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.","triggerScenarios":"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.","commonSituations":"Truncated or corrupt CID CMap; wrong stream referenced as a CMap; PDF produced by a faulty font tool.","solutions":["Repair or regenerate the PDF.","Update pdf.js.","Catch FormatError and continue without that CMap (degrades CID text extraction)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await loadingTask.promise;\n} catch (e) {\n  if (e instanceof FormatError && /expected int/.test(e.message)) {\n    console.warn('Malformed CMap (expected int), CID mapping may degrade', e);\n  } else throw e;\n}","preventionTips":["Validate untrusted PDFs before rendering.","Keep pdf.js updated.","Validate generated CID CMaps parse cleanly before shipping PDFs.","Treat CMap parse failures as non-fatal where rendering can proceed."],"tags":["cmap","font","parsing","pdf"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}