{"record":{"id":"408df61f62ae4e4b","repo":"mozilla/pdf.js","slug":"parsefdselect-invalid-font-data","errorCode":null,"errorMessage":"parseFDSelect: Invalid font data.","messagePattern":"parseFDSelect: Invalid font data\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/cff_parser.js","lineNumber":1100,"sourceCode":"              \"parseFDSelect: The first range must have a first GID of 0\" +\n                \" -- trying to recover.\"\n            );\n            first = 0;\n          }\n          const fdIndex = bytes[pos++];\n          const next = (bytes[pos] << 8) | bytes[pos + 1];\n          for (let j = first; j < next; ++j) {\n            fdSelect.push(fdIndex);\n          }\n        }\n        // Advance past the sentinel(next).\n        pos += 2;\n        break;\n      default:\n        throw new FormatError(`parseFDSelect: Unknown format \"${format}\".`);\n    }\n    if (fdSelect.length !== length) {\n      throw new FormatError(\"parseFDSelect: Invalid font data.\");\n    }\n\n    return new CFFFDSelect(format, fdSelect);\n  }\n}\n\n// Compact Font Format\nclass CFF {\n  header = null;\n\n  names = [];\n\n  topDict = null;\n\n  strings = new CFFStrings();\n\n  globalSubrIndex = null;\n","sourceCodeStart":1082,"sourceCodeEnd":1118,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/cff_parser.js#L1082-L1118","documentation":"Thrown by CFFParser.parseFDSelect after the table is parsed when the resulting fdSelect array length does not equal the expected glyph count. This means the FDSelect ranges/entries did not cover every glyph, indicating truncated or corrupt FDSelect data.","triggerScenarios":"Parsing a CIDFont FDSelect (format 0 or 3) that yields fewer or more entries than the number of glyphs (the `length` argument). The post-loop guard `fdSelect.length !== length` fires.","commonSituations":"FDSelect ranges cut short by truncation; corrupt sentinel values in format-3 ranges; mismatch between FDSelect coverage and CharStrings count after faulty subsetting; damaged font streams.","solutions":["Accept pdf.js's font substitution fallback.","Re-embed or repair the CIDFont with fontTools/Ghostscript so FDSelect covers all glyphs.","Validate FDSelect length against glyph count during font generation."],"exampleFix":"// pdf.js falls back to a system font; caller observes via render promise.\ntry {\n  await page.render({ canvasContext, viewport }).promise;\n} catch (e) {\n  console.warn('Render failed due to invalid FDSelect data:', e);\n}","handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await page.render({ canvasContext, viewport }).promise;\n} catch (e) {\n  // FDSelect coverage mismatch; pdf.js falls back to a system font.\n  console.warn('Invalid FDSelect data:', e);\n}","preventionTips":["Ensure FDSelect covers exactly all glyphs when subsetting CIDFonts.","Validate FDSelect length against glyph count during font generation.","Re-embed corrupt CIDFonts via fontTools/Ghostscript."],"tags":["font","cff","cff-parser","fdselect","cidfont","corrupt-font"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}