{"record":{"id":"720115716918fbaf","repo":"mozilla/pdf.js","slug":"mapcidrange-ignoring-data-above-max-map-range","errorCode":null,"errorMessage":"mapCidRange - ignoring data above MAX_MAP_RANGE.","messagePattern":"mapCidRange - ignoring data above MAX_MAP_RANGE\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/cmap.js","lineNumber":227,"sourceCode":"    // Map entries have one of two forms.\n    // - cid chars are 16-bit unsigned integers, stored as integers.\n    // - bf chars are variable-length byte sequences, stored as strings, with\n    //   one byte per character.\n    this._map = [];\n    this.name = \"\";\n    this.vertical = false;\n    this.useCMap = null;\n    this.builtInCMap = builtInCMap;\n  }\n\n  addCodespaceRange(n, low, high) {\n    this.codespaceRanges[n - 1].push(low, high);\n    this.numCodespaceRanges++;\n  }\n\n  mapCidRange(low, high, dstLow) {\n    if (high - low > MAX_MAP_RANGE) {\n      throw new Error(\"mapCidRange - ignoring data above MAX_MAP_RANGE.\");\n    }\n    while (low <= high) {\n      this._map[low++] = dstLow++;\n    }\n  }\n\n  mapBfRange(low, high, dstLow) {\n    if (high - low > MAX_MAP_RANGE) {\n      throw new Error(\"mapBfRange - ignoring data above MAX_MAP_RANGE.\");\n    }\n    const lastByte = dstLow.length - 1;\n    while (low <= high) {\n      this._map[low++] = dstLow;\n      // Only the last byte has to be incremented (in the normal case).\n      const nextCharCode = dstLow.charCodeAt(lastByte) + 1;\n      if (nextCharCode > 0xff) {\n        dstLow =\n          dstLow.substring(0, lastByte - 1) +","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/cmap.js#L209-L245","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nconst cmap = await CMapFactory.create({ encoding, fetchBuiltInCMap, useCMap });\n\n// after\nlet cmap;\ntry {\n  cmap = await CMapFactory.create({ encoding, fetchBuiltInCMap, useCMap });\n} catch (e) {\n  if (/MAX_MAP_RANGE/.test(e.message)) {\n    console.warn('Oversized CMap cid range, skipping', e);\n    cmap = null;\n  } else throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  cmap = await CMapFactory.create({ encoding, fetchBuiltInCMap, useCMap });\n} catch (e) {\n  if (/MAX_MAP_RANGE/.test(e.message)) {\n    console.warn('Oversized cid range in CMap, skipping', e);\n    cmap = null; // degrade: no CID mapping for this font\n  } else {\n    throw e;\n  }\n}","preventionTips":["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."],"tags":["cmap","font","parsing","memory","pdf"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}