{"record":{"id":"5656c261f9b75627","repo":"mozilla/pdf.js","slug":"unknown-charset-format","errorCode":null,"errorMessage":"Unknown charset format","messagePattern":"Unknown charset format","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/cff_parser.js","lineNumber":988,"sourceCode":"        while (charset.length <= length) {\n          id = (bytes[pos++] << 8) | bytes[pos++];\n          count = bytes[pos++];\n          for (i = 0; i <= count; i++) {\n            charset.push(cid ? id++ : strings.get(id++));\n          }\n        }\n        break;\n      case 2:\n        while (charset.length <= length) {\n          id = (bytes[pos++] << 8) | bytes[pos++];\n          count = (bytes[pos++] << 8) | bytes[pos++];\n          for (i = 0; i <= count; i++) {\n            charset.push(cid ? id++ : strings.get(id++));\n          }\n        }\n        break;\n      default:\n        throw new FormatError(\"Unknown charset format\");\n    }\n\n    return new CFFCharset(false, format, charset);\n  }\n\n  parseEncoding(pos, properties, strings, charset) {\n    const encoding = Object.create(null);\n    const bytes = this.bytes;\n    let predefined = false;\n    let format, i, ii;\n    let raw = null;\n\n    function readSupplement() {\n      const supplementsCount = bytes[pos++];\n      for (i = 0; i < supplementsCount; i++) {\n        const code = bytes[pos++];\n        const sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);\n        encoding[code] = charset.indexOf(strings.get(sid));","sourceCodeStart":970,"sourceCodeEnd":1006,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/cff_parser.js#L970-L1006","documentation":"Thrown by CFFParser.parseCharset when the charset table's format byte is not one of the three spec-defined values (0, 1, or 2). The default branch of the format switch fires, indicating a corrupt or non-standard charset table.","triggerScenarios":"Parsing a CFF font whose charset table begins with a format byte outside {0,1,2}. Reached after predefined-charset shortcuts (ISOAdobe/Expert/ExpertSubset) are skipped and `format = bytes[pos++]` is read.","commonSituations":"Corrupt CFF charset tables in embedded fonts; damaged font streams; fonts produced by tools that write invalid charset format identifiers; CIDFont streams with mangled charset data.","solutions":["Rely on pdf.js's font substitution path, which catches the FormatError and falls back.","Repair or re-embed the font using fontTools or Ghostscript.","Re-validate embedded fonts in your generation pipeline before writing the PDF."],"exampleFix":"// Caller observes via render promise; pdf.js substitutes a fallback.\ntry {\n  await page.render({ canvasContext, viewport }).promise;\n} catch (e) {\n  console.warn('Render failed due to corrupt CFF charset:', e);\n}","handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await page.render({ canvasContext, viewport }).promise;\n} catch (e) {\n  // Corrupt CFF charset; pdf.js falls back to a system font.\n  console.warn('Unknown CFF charset format:', e);\n}","preventionTips":["Validate CFF charset format bytes (must be 0, 1, or 2) when authoring fonts.","Re-embed fonts with fontTools to repair corrupt charset tables.","Accept pdf.js font substitution for untrusted PDFs."],"tags":["font","cff","cff-parser","charset","corrupt-font"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}