mozilla/pdf.js · error · Error
mapCidRange - ignoring data above MAX_MAP_RANGE.
Error message
mapCidRange - ignoring data above MAX_MAP_RANGE.
What it means
Thrown by CMap.mapCidRange when a single cidrange operator spans more than MAX_MAP_RANGE (2^24 - 1 = 16,777,215) code points. The cap prevents the _map array from being expanded into gigabytes of memory by one oversized range. It indicates the CMap (usually embedded in a PDF font) is malformed or actively hostile.
Source
Thrown at src/core/cmap.js:227
// Map entries have one of two forms.
// - cid chars are 16-bit unsigned integers, stored as integers.
// - bf chars are variable-length byte sequences, stored as strings, with
// one byte per character.
this._map = [];
this.name = "";
this.vertical = false;
this.useCMap = null;
this.builtInCMap = builtInCMap;
}
addCodespaceRange(n, low, high) {
this.codespaceRanges[n - 1].push(low, high);
this.numCodespaceRanges++;
}
mapCidRange(low, high, dstLow) {
if (high - low > MAX_MAP_RANGE) {
throw new Error("mapCidRange - ignoring data above MAX_MAP_RANGE.");
}
while (low <= high) {
this._map[low++] = dstLow++;
}
}
mapBfRange(low, high, dstLow) {
if (high - low > MAX_MAP_RANGE) {
throw new Error("mapBfRange - ignoring data above MAX_MAP_RANGE.");
}
const lastByte = dstLow.length - 1;
while (low <= high) {
this._map[low++] = dstLow;
// Only the last byte has to be incremented (in the normal case).
const nextCharCode = dstLow.charCodeAt(lastByte) + 1;
if (nextCharCode > 0xff) {
dstLow =
dstLow.substring(0, lastByte - 1) +View on GitHub (pinned to 5903d58d58)
Solutions
- Open the PDF in an authoritative reader; if it also fails, the CMap is corrupt - regenerate the PDF or the font subset.
- Update pdf.js; newer versions handle oversized ranges more gracefully in some code paths.
- If you control the PDF pipeline, split each cidrange into multiple ranges no wider than 0xFFFFFF.
- Wrap CMap loading in try/catch and degrade (skip ToUnicode / fall back to a replacement font).
Example fix
// before
const cmap = await CMapFactory.create({ encoding, fetchBuiltInCMap, useCMap });
// after
let cmap;
try {
cmap = await CMapFactory.create({ encoding, fetchBuiltInCMap, useCMap });
} catch (e) {
if (/MAX_MAP_RANGE/.test(e.message)) {
console.warn('Oversized CMap cid range, skipping', e);
cmap = null;
} else throw e;
} Defensive patterns
Strategy: try-catch
Try / catch
try {
cmap = await CMapFactory.create({ encoding, fetchBuiltInCMap, useCMap });
} catch (e) {
if (/MAX_MAP_RANGE/.test(e.message)) {
console.warn('Oversized cid range in CMap, skipping', e);
cmap = null; // degrade: no CID mapping for this font
} else {
throw e;
}
} Prevention
- Run PDFs from untrusted sources through a sanitizer before rendering.
- Keep pdf.js updated for stricter CMap handling.
- Avoid shipping PDFs produced by broken font-subsetting tools.
- When authoring CID CMaps, keep each cidrange <= 0xFFFFFF code points.
When it happens
Trigger: Parsing a CMap whose begincidrange ... endcidrange block declares a line <low> <high> <dst> where high - low > 0xFFFFFF. Triggered while resolving a CID font's encoding during text extraction or rendering.
Common situations: Corrupted or hand-edited CID-keyed font CMap; a fuzzed or malicious PDF crafted to exhaust memory; a buggy font-subsetting tool that emits one giant range instead of many small ones.
Related errors
- mapBfRange - ignoring data above MAX_MAP_RANGE.
- mapBfRangeToArray - ignoring data above MAX_MAP_RANGE.
- Malformed CMap: expected string.
- Malformed CMap: expected int.
- Invalid bf range.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/720115716918fbaf.
Report an issue: GitHub.