mozilla/pdf.js · error · FormatError
parseFDSelect: Invalid font data.
Error message
parseFDSelect: Invalid font data.
What it means
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.
Source
Thrown at src/core/cff_parser.js:1100
"parseFDSelect: The first range must have a first GID of 0" +
" -- trying to recover."
);
first = 0;
}
const fdIndex = bytes[pos++];
const next = (bytes[pos] << 8) | bytes[pos + 1];
for (let j = first; j < next; ++j) {
fdSelect.push(fdIndex);
}
}
// Advance past the sentinel(next).
pos += 2;
break;
default:
throw new FormatError(`parseFDSelect: Unknown format "${format}".`);
}
if (fdSelect.length !== length) {
throw new FormatError("parseFDSelect: Invalid font data.");
}
return new CFFFDSelect(format, fdSelect);
}
}
// Compact Font Format
class CFF {
header = null;
names = [];
topDict = null;
strings = new CFFStrings();
globalSubrIndex = null;
View on GitHub (pinned to 5903d58d58)
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.
Example fix
// pdf.js falls back to a system font; caller observes via render promise.
try {
await page.render({ canvasContext, viewport }).promise;
} catch (e) {
console.warn('Render failed due to invalid FDSelect data:', e);
} Defensive patterns
Strategy: fallback
Validate before calling
null
Type guard
null
Try / catch
try {
await page.render({ canvasContext, viewport }).promise;
} catch (e) {
// FDSelect coverage mismatch; pdf.js falls back to a system font.
console.warn('Invalid FDSelect data:', e);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- parseFDSelect: Unknown format "${format}".
- Invalid CFF header
- CFF Private DICT extends past end of font
- Unknown charset format
- Unknown encoding format: ${format} in CFF
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/408df61f62ae4e4b.
Report an issue: GitHub.