mozilla/pdf.js · error · FormatError
Max size of CID is 65,535
Error message
Max size of CID is 65,535
What it means
Thrown while building the ToUnicode map for a CID font when iterating the font's CMap and encountering a character identifier (CID) greater than 0xFFFF (65,535). CID values are 16-bit by definition; a larger value indicates a corrupt CMap or a CIDSystemInfo/registry mismatch. The check guards against array-index overflow in the toUnicode lookup table.
Source
Thrown at src/core/evaluator.js:3988
// by the font’s CMap (for example, Adobe and Japan1) from its
// CIDSystemInfo dictionary.
const { registry, ordering } = properties.cidSystemInfo;
// c) Construct a second CMap name by concatenating the registry and
// ordering obtained in step (b) in the format registry–ordering–UCS2
// (for example, Adobe–Japan1–UCS2).
const ucs2CMapName = Name.get(`${registry}-${ordering}-UCS2`);
// d) Obtain the CMap with the name constructed in step (c) (available
// from the ASN Web site; see the Bibliography).
const ucs2CMap = await CMapFactory.create({
encoding: ucs2CMapName,
fetchBuiltInCMap: this._fetchBuiltInCMapBound,
useCMap: null,
});
const toUnicode = [],
buf = [];
properties.cMap.forEach(function (charcode, cid) {
if (cid > 0xffff) {
throw new FormatError("Max size of CID is 65,535");
}
// e) Map the CID obtained in step (a) according to the CMap
// obtained in step (d), producing a Unicode value.
const ucs2 = ucs2CMap.lookup(cid);
if (ucs2) {
buf.length = 0;
// Support multi-byte entries (fixes issue16176.pdf).
for (let i = 0, ii = ucs2.length; i < ii; i += 2) {
buf.push((ucs2.charCodeAt(i) << 8) + ucs2.charCodeAt(i + 1));
}
toUnicode[charcode] = String.fromCharCode(...buf);
}
});
return new ToUnicodeMap(toUnicode);
}
// The viewer's choice, just use an identity map.
return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar);View on GitHub (pinned to 5903d58d58)
Solutions
- Repair or regenerate the CMap data in the offending font; ensure CID values fit in 16 bits.
- Re-export the PDF through Ghostscript (gs -sDEVICE=pdfwrite) which normalizes CID/CMap structures.
- Catch the error per-page and continue rendering with an incomplete ToUnicode map (search/copy fidelity will suffer).
- If authoring CJK content with a custom tool, validate CID ranges against the relevant Adobe CMap resource before embedding.
Example fix
// before
await page.getTextContent(); // throws if a CID > 0xFFFF
// after
try {
await page.getTextContent();
} catch (e) {
if (/Max size of CID/.test(e.message)) {
console.warn('CID font corrupt, text extraction will be partial');
} else throw e;
} Defensive patterns
Strategy: try-catch
Try / catch
try {
await page.getTextContent();
} catch (e) {
if (e.name === 'FormatError' && /Max size of CID/.test(e.message)) {
// CID font corrupt; accept partial text extraction
} else throw e;
} Prevention
- Validate embedded CMap data against the relevant Adobe CMap spec for CID ranges before publishing CJK PDFs.
- Re-export CJK PDFs through Ghostscript to normalize CID/CMap structures.
- Isolate per-page operations so one corrupt CID font does not block other pages.
When it happens
Trigger: A composite (Type0/CID) font whose CMap yields a CID > 65535 during the registry-ordering-UCS2 mapping step. Fires in buildToUnicode() inside PartialEvaluator, only for fonts whose CIDSystemInfo is one of the standard Adobe collections (GB1, CNS1, Japan1, Korea1).
Common situations: Corrupt or hand-built CMap data, a CID font whose CMap was concatenated with a wrong/use CMap, or a generator that emitted non-truncated CID ranges. Rare in the wild but seen in PDFs produced by experimental or academic CJK typesetting tools.
Related errors
- Unknown CMap name: ${name}
- Built-in CMap parameters are not provided.
- Unsupported CID string (charCode ${charCode}): "${cid}".
- Max size of CID is 65,535
- mapCidRange - ignoring data above MAX_MAP_RANGE.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/fb170e84d5b13d23.
Report an issue: GitHub.