{"record":{"id":"0427dc1f52005fd2","repo":"mozilla/pdf.js","slug":"max-size-of-cid-is-65-535-0427dc","errorCode":null,"errorMessage":"Max size of CID is 65,535","messagePattern":"Max size of CID is 65,535","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/fonts.js","lineNumber":3047,"sourceCode":"    };\n\n    const charCodeToGlyphId = Object.create(null);\n\n    // Helper function to try to skip mapping of empty glyphs.\n    function hasGlyph(glyphId) {\n      return !missingGlyphs[glyphId];\n    }\n\n    if (properties.composite) {\n      const cidToGidMap = properties.cidToGidMap || [];\n      const isCidToGidMapEmpty = cidToGidMap.length === 0;\n\n      properties.cMap.forEach(function (charCode, cid) {\n        if (typeof cid === \"string\") {\n          cid = convertCidString(charCode, cid, /* shouldThrow = */ true);\n        }\n        if (cid > 0xffff) {\n          throw new FormatError(\"Max size of CID is 65,535\");\n        }\n        let glyphId = -1;\n        if (isCidToGidMapEmpty) {\n          glyphId = cid;\n        } else if (cidToGidMap[cid] !== undefined) {\n          glyphId = cidToGidMap[cid];\n        }\n\n        if (glyphId >= 0 && glyphId < numGlyphs && hasGlyph(glyphId)) {\n          charCodeToGlyphId[charCode] = glyphId;\n        }\n      });\n    } else {\n      // Most of the following logic in this code branch is based on the\n      // 9.6.6.4 of the PDF spec.\n      const cmapTable = readCmapTable(\n        tables.cmap,\n        font,","sourceCodeStart":3029,"sourceCodeEnd":3065,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/fonts.js#L3029-L3065","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["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.","Ensure the CIDSystemInfo (Registry/Ordering/Supplement) in the PDF matches the CMap being used.","Rebuild the PDF's composite font with a correct CMap (e.g., Identity-H maps 2-byte charCodes directly to CIDs 0–65535).","If the CMap is corrupt, replace it with the appropriate standard CMap for the font's writing system."],"exampleFix":"% PDF CMap fix — ensure CID values stay within 16-bit range\n% before (corrupt CMap with oversized CID):\n1 beginbfchar\n<0001> <00100001>  % CID 65537 — exceeds 16-bit limit\nendbfchar\n\n% after — valid 16-bit CID:\n1 beginbfchar\n<0001> <0001>  % CID 1 — within range\nendbfchar","handlingStrategy":"validation","validationCode":"// Server-side: verify CMap CID values are within 16-bit range\n// Parse the CMap resource and check that all CID values are <= 0xFFFF.\n// Adobe CMap resources define CID mappings; any value > 65535 is invalid.\nfunction validateCMapCidRange(cmapEntries) {\n  // cmapEntries: array of { charCode, cid }\n  for (const { charCode, cid } of cmapEntries) {\n    if (cid > 0xFFFF) {\n      return { ok: false, charCode, cid, reason: `CID ${cid} exceeds 16-bit limit` };\n    }\n  }\n  return { ok: true };\n}","typeGuard":null,"tryCatchPattern":"try {\n  await page.render(renderParams).promise;\n} catch (err) {\n  if (err.message?.includes('Max size of CID is 65,535')) {\n    console.error('CMap contains CID values exceeding 16-bit limit; fix the CMap resource.');\n  } else { throw err; }\n}","preventionTips":["Use standard Adobe CMap resources that are guaranteed to produce 16-bit CIDs.","Verify CIDSystemInfo (Registry/Ordering/Supplement) matches the CMap being used.","Validate CMap files for CID range compliance before embedding in PDFs."],"tags":["font","cid","cmap","composite-font","cidfont","format-error"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}