{"record":{"id":"7be5b16eca4df40e","repo":"mozilla/pdf.js","slug":"invalid-bf-range","errorCode":null,"errorMessage":"Invalid bf range.","messagePattern":"Invalid bf range\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/cmap.js","lineNumber":511,"sourceCode":"    expectString(obj);\n    const high = strToInt(obj);\n    obj = lexer.getObj();\n    if (Number.isInteger(obj) || typeof obj === \"string\") {\n      const dstLow = Number.isInteger(obj) ? String.fromCharCode(obj) : obj;\n      cMap.mapBfRange(low, high, dstLow);\n    } else if (isCmd(obj, \"[\")) {\n      obj = lexer.getObj();\n      const array = [];\n      while (!isCmd(obj, \"]\") && obj !== EOF) {\n        array.push(obj);\n        obj = lexer.getObj();\n      }\n      cMap.mapBfRangeToArray(low, high, array);\n    } else {\n      break;\n    }\n  }\n  throw new FormatError(\"Invalid bf range.\");\n}\n\nfunction parseCidChar(cMap, lexer) {\n  while (true) {\n    let obj = lexer.getObj();\n    if (obj === EOF) {\n      break;\n    }\n    if (isCmd(obj, \"endcidchar\")) {\n      return;\n    }\n    expectString(obj);\n    const src = strToInt(obj);\n    obj = lexer.getObj();\n    expectInt(obj);\n    const dst = obj;\n    cMap.mapOne(src, dst);\n  }","sourceCodeStart":493,"sourceCodeEnd":529,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/cmap.js#L493-L529","documentation":"Thrown at the end of parseBfChar when its token loop exits without encountering endbfrange - that is, the bfrange block is truncated or its tokens do not match any of the expected forms (hex string, Name, or the [ ... ] array form), causing the loop's else break. Indicates an incomplete or malformed bfrange section.","triggerScenarios":"A beginbfrange ... endbfrange block that is truncated, contains an unexpected token type that triggers the break, or hits EOF before the endbfrange marker.","commonSituations":"Truncated ToUnicode stream embedded in the PDF; CMap stream cut off by a broken indirect-object resolution; a hand-edited CMap missing its terminator.","solutions":["Repair or regenerate the PDF.","Update pdf.js; later versions are more tolerant of some malformed shapes.","Catch FormatError during load and fall back to rendering without ToUnicode."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await loadingTask.promise;\n} catch (e) {\n  if (e instanceof FormatError && /Invalid bf range/.test(e.message)) {\n    console.warn('Truncated bfrange in CMap, ToUnicode may be incomplete', e);\n  } else throw e;\n}","preventionTips":["Validate untrusted PDFs before rendering.","Keep pdf.js updated for more tolerant bfrange parsing.","When authoring CMaps, always emit the endbfrange terminator.","Treat ToUnicode parse failures as non-fatal for rendering."],"tags":["cmap","tounicode","font","parsing","pdf"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}