{"record":{"id":"79b12f4c8225f830","repo":"mozilla/pdf.js","slug":"invalid-codespace-range","errorCode":null,"errorMessage":"Invalid codespace range.","messagePattern":"Invalid codespace range\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/cmap.js","lineNumber":573,"sourceCode":"    let obj = lexer.getObj();\n    if (obj === EOF) {\n      break;\n    }\n    if (isCmd(obj, \"endcodespacerange\")) {\n      return;\n    }\n    if (typeof obj !== \"string\") {\n      break;\n    }\n    const low = strToInt(obj);\n    obj = lexer.getObj();\n    if (typeof obj !== \"string\") {\n      break;\n    }\n    const high = strToInt(obj);\n    cMap.addCodespaceRange(obj.length, low, high);\n  }\n  throw new FormatError(\"Invalid codespace range.\");\n}\n\nfunction parseWMode(cMap, lexer) {\n  const obj = lexer.getObj();\n  if (Number.isInteger(obj)) {\n    cMap.vertical = !!obj;\n  }\n}\n\nfunction parseCMapName(cMap, lexer) {\n  const obj = lexer.getObj();\n  if (obj instanceof Name) {\n    cMap.name = obj.name;\n  }\n}\n\nasync function parseCMap(cMap, lexer, fetchBuiltInCMap, useCMap) {\n  let previous, embeddedUseCMap;","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/cmap.js#L555-L591","documentation":"Thrown by parseCodespaceRanges when its token loop exits without finding endcodespacerange - the codespace declaration is incomplete or its low/high tokens are not hex strings (the loop breaks on a non-string token). The codespace is the foundational part of a CMap, so an incomplete one is unrecoverable.","triggerScenarios":"Parsing a CMap whose begincodespacerange block is truncated, whose low/high tokens are not strings, or which hits EOF before endcodespacerange.","commonSituations":"Corrupt or truncated CMap; the wrong stream referenced as a CMap; a CMap produced by a buggy writer that omitted the codespace terminator.","solutions":["Repair or regenerate the PDF.","Update pdf.js.","Catch FormatError and degrade gracefully for that font."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await loadingTask.promise;\n} catch (e) {\n  if (e instanceof FormatError && /Invalid codespace range/.test(e.message)) {\n    console.warn('Truncated codespace in CMap, font mapping will degrade', e);\n  } else throw e;\n}","preventionTips":["Validate untrusted PDFs before rendering.","Keep pdf.js updated.","When authoring CMaps, always emit endcodespacerange.","Ensure /ToUnicode and /Encoding actually point at CMap streams, not arbitrary objects."],"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"}