mozilla/pdf.js · error · FormatError
parseFDSelect: Unknown format "${format}".
Error message
parseFDSelect: Unknown format "${format}". What it means
Thrown by CFFParser.parseFDSelect when the FDSelect table (CIDFont-only) has a format byte that is neither 0 nor 3 (the only defined formats). The default branch fires, indicating a corrupt FDSelect table.
Source
Thrown at src/core/cff_parser.js:1097
let first = (bytes[pos++] << 8) | bytes[pos++];
if (i === 0 && first !== 0) {
warn(
"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();View on GitHub (pinned to 5903d58d58)
Solutions
- Let pdf.js fall back to a system font (it catches this FormatError).
- Repair or re-embed the CIDFont using fontTools (ttx) or Ghostscript.
- Re-subset the font with a compliant tool if produced in-house.
Example fix
// pdf.js substitutes a fallback font; observe via render promise.
try {
await page.render({ canvasContext, viewport }).promise;
} catch (e) {
console.warn('Render failed due to corrupt FDSelect format:', e);
} Defensive patterns
Strategy: fallback
Validate before calling
null
Type guard
null
Try / catch
try {
await page.render({ canvasContext, viewport }).promise;
} catch (e) {
// Corrupt CIDFont FDSelect format; pdf.js falls back to a system font.
console.warn('Unknown FDSelect format:', e);
} Prevention
- Validate FDSelect format bytes (must be 0 or 3) when authoring CIDFonts.
- Re-subset CIDFonts with a compliant tool before embedding.
- Accept pdf.js font substitution for untrusted CIDFont PDFs.
When it happens
Trigger: Parsing a CID-keyed CFF font whose FDSelect table begins with a format byte outside {0,3}. FDSelect maps each glyph to a Font DICT index and only formats 0 (per-glyph bytes) and 3 (ranges) are defined.
Common situations: Corrupt CIDFont FDSelect tables in embedded CFF2/CFF fonts; damaged font streams; output from subsetting tools that wrote an invalid FDSelect format; CFF2 fonts misrouted through the legacy CFF parser.
Related errors
- parseFDSelect: Invalid font data.
- 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/42e2cdebfb76d632.
Report an issue: GitHub.