mozilla/pdf.js · error · Error
mapBfRangeToArray - ignoring data above MAX_MAP_RANGE.
Error message
mapBfRangeToArray - ignoring data above MAX_MAP_RANGE.
What it means
Thrown by CMap.mapBfRangeToArray when the array-form bfrange (beginbfrange ... [ ... ] ... endbfrange) declares a range wider than MAX_MAP_RANGE (2^24 - 1). Same guard as the other map*Range methods but for the array-destination variant where each code maps to a listed entry.
Source
Thrown at src/core/cmap.js:257
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) +
String.fromCharCode(dstLow.charCodeAt(lastByte - 1) + 1) +
"\x00";
continue;
}
dstLow =
dstLow.substring(0, lastByte) + String.fromCharCode(nextCharCode);
}
}
mapBfRangeToArray(low, high, array) {
if (high - low > MAX_MAP_RANGE) {
throw new Error("mapBfRangeToArray - ignoring data above MAX_MAP_RANGE.");
}
const ii = array.length;
let i = 0;
while (low <= high && i < ii) {
this._map[low] = array[i++];
++low;
}
}
// This is used for both bf and cid chars.
mapOne(src, dst) {
this._map[src] = dst;
}
lookup(code) {
return this._map[code];
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Regenerate the PDF or its ToUnicode stream.
- Update pdf.js.
- Author CMaps with array-bfrange ranges no wider than 0xFFFFFF.
- Catch FormatError/Error and degrade text extraction for that 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 bf-array 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 bf-array range in CMap, skipping', e);
cmap = null;
} else {
throw e;
}
} Prevention
- Sanitize untrusted PDFs before rendering.
- Keep pdf.js updated.
- When authoring array-form bfrange CMaps, keep each range <= 0xFFFFFF.
- Validate generated CMaps with a round-trip parse before shipping.
When it happens
Trigger: Parsing a CMap where a beginbfrange line uses the [<low> <high> [<d0> <d1> ...]] array form and high - low > 0xFFFFFF.
Common situations: Corrupt or hand-crafted ToUnicode CMap using the array bfrange form with an absurdly wide range; malicious PDF.
Related errors
- mapBfRange - ignoring data above MAX_MAP_RANGE.
- mapCidRange - ignoring data above MAX_MAP_RANGE.
- Malformed CMap: expected string.
- Invalid bf range.
- Malformed CMap: expected int.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/f8540a16f3943bb7.
Report an issue: GitHub.