mozilla/pdf.js · error · Error
mapBfRange - ignoring data above MAX_MAP_RANGE.
Error message
mapBfRange - ignoring data above MAX_MAP_RANGE.
What it means
Thrown by CMap.mapBfRange when a beginbfrange entry spans more than MAX_MAP_RANGE (2^24 - 1) code points. Same memory guard as mapCidRange but for the string-destination bf range form used in ToUnicode CMaps. Indicates a malformed or hostile ToUnicode stream.
Source
Thrown at src/core/cmap.js:236
}
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) +
String.fromCharCode(dstLow.charCodeAt(lastByte - 1) + 1) +
"\x00";
continue;
}
dstLow =
dstLow.substring(0, lastByte) + String.fromCharCode(nextCharCode);
}
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Repair or regenerate the PDF; an authoritative reader should also reject it.
- Update pdf.js for stricter/safer CMap handling.
- Split the offending bfrange into multiple ranges each <= 0xFFFFFF wide if you author CMaps.
- Catch the error and continue without ToUnicode (text selection accuracy degrades but rendering works).
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 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 range in CMap, skipping', e);
cmap = null;
} else {
throw e;
}
} Prevention
- Sanitize untrusted PDFs before rendering.
- Keep pdf.js updated.
- When generating ToUnicode CMaps, keep each bfrange <= 0xFFFFFF.
- Treat any single-range CMap wider than 16M as a defect in your PDF pipeline.
When it happens
Trigger: Parsing a CMap whose beginbfrange ... endbfrange block contains <low> <high> <dst-string> where high - low > 0xFFFFFF. Hit while building a font's ToUnicode mapping for text search/selection/copy.
Common situations: Corrupt ToUnicode CMap emitted by a broken PDF writer; malicious PDF designed to balloon memory; truncated CMap reassembled incorrectly.
Related errors
- mapBfRangeToArray - 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/c16a702efc52369d.
Report an issue: GitHub.