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 during composite font charCodeToGlyphId mapping when a CID (Character ID) value exceeds 0xFFFF (65,535). CIDs in PDF composite fonts are 16-bit quantities; a value above this limit cannot be stored in the glyph ID array and violates the CIDFont specification.

Source

Thrown at src/core/fonts.js:3047

    };

    const charCodeToGlyphId = Object.create(null);

    // Helper function to try to skip mapping of empty glyphs.
    function hasGlyph(glyphId) {
      return !missingGlyphs[glyphId];
    }

    if (properties.composite) {
      const cidToGidMap = properties.cidToGidMap || [];
      const isCidToGidMapEmpty = cidToGidMap.length === 0;

      properties.cMap.forEach(function (charCode, cid) {
        if (typeof cid === "string") {
          cid = convertCidString(charCode, cid, /* shouldThrow = */ true);
        }
        if (cid > 0xffff) {
          throw new FormatError("Max size of CID is 65,535");
        }
        let glyphId = -1;
        if (isCidToGidMapEmpty) {
          glyphId = cid;
        } else if (cidToGidMap[cid] !== undefined) {
          glyphId = cidToGidMap[cid];
        }

        if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId)) {
          charCodeToGlyphId[charCode] = glyphId;
        }
      });
    } else {
      // Most of the following logic in this code branch is based on the
      // 9.6.6.4 of the PDF spec.
      const cmapTable = readCmapTable(
        tables.cmap,
        font,

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Verify the CMap resource is well-formed and emits only 16-bit CID values — inspect it with a CMap viewer or the Adobe CMap resource repository.
  2. Ensure the CIDSystemInfo (Registry/Ordering/Supplement) in the PDF matches the CMap being used.
  3. Rebuild the PDF's composite font with a correct CMap (e.g., Identity-H maps 2-byte charCodes directly to CIDs 0–65535).
  4. If the CMap is corrupt, replace it with the appropriate standard CMap for the font's writing system.

Example fix

% PDF CMap fix — ensure CID values stay within 16-bit range
% before (corrupt CMap with oversized CID):
1 beginbfchar
<0001> <00100001>  % CID 65537 — exceeds 16-bit limit
endbfchar

% after — valid 16-bit CID:
1 beginbfchar
<0001> <0001>  % CID 1 — within range
endbfchar
Defensive patterns

Strategy: validation

Validate before calling

// Server-side: verify CMap CID values are within 16-bit range
// Parse the CMap resource and check that all CID values are <= 0xFFFF.
// Adobe CMap resources define CID mappings; any value > 65535 is invalid.
function validateCMapCidRange(cmapEntries) {
  // cmapEntries: array of { charCode, cid }
  for (const { charCode, cid } of cmapEntries) {
    if (cid > 0xFFFF) {
      return { ok: false, charCode, cid, reason: `CID ${cid} exceeds 16-bit limit` };
    }
  }
  return { ok: true };
}

Try / catch

try {
  await page.render(renderParams).promise;
} catch (err) {
  if (err.message?.includes('Max size of CID is 65,535')) {
    console.error('CMap contains CID values exceeding 16-bit limit; fix the CMap resource.');
  } else { throw err; }
}

Prevention

When it happens

Trigger: In properties.cMap.forEach, after converting a CID string via convertCidString (or using a numeric CID), the check if (cid > 0xffff) at line 3046 throws. This means the CMap yields CID values outside the 16-bit range, or convertCidString produced a value > 0xFFFF from a 2-byte string (impossible for valid 2-byte strings, so this typically indicates a numeric CID from the CMap iterator that exceeds the limit).

Common situations: A corrupt CMap file that emits CID values above 65535. A CIDToGIDMap or CMap resource with incorrect byte ordering that produces oversized values. Non-standard composite fonts with buggy CMap generation. PDFs from producers that misuse the CMap CID encoding. An off-by-one or overflow in the CMap parsing logic for a specific CMap variant.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/0427dc1f52005fd2. Report an issue: GitHub.