{"record":{"id":"00fe0770ad1bbdb0","repo":"mozilla/pdf.js","slug":"unknown-type-type","errorCode":null,"errorMessage":"Unknown type: ${type}","messagePattern":"Unknown type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"external/cmapscompress/compress.mjs","lineNumber":350,"sourceCode":"          subitems.push({ char, code });\n        }\n        break;\n      case 5:\n        start = reader.readHex(ucs2DataSize);\n        end = addHex(reader.readHexNumber(ucs2DataSize), start);\n        code = reader.readHex(dataSize);\n        subitems.push({ start, end, code });\n        for (let i = 1; i < subitemsCount; i++) {\n          start = sequence\n            ? incHex(end)\n            : addHex(reader.readHexNumber(ucs2DataSize), incHex(end));\n          end = addHex(reader.readHexNumber(ucs2DataSize), start);\n          code = reader.readHex(dataSize);\n          subitems.push({ start, end, code });\n        }\n        break;\n      default:\n        throw new Error(\"Unknown type: \" + type);\n    }\n    result.body.push(item);\n  }\n\n  return result;\n}\n\nfunction toHexDigit(n) {\n  return n.toString(16);\n}\nfunction fromHexDigit(s) {\n  return parseInt(s, 16);\n}\nfunction getHexSize(s) {\n  return (s.length >> 1) - 1;\n}\nfunction writeByte(b) {\n  return toHexDigit((b >> 4) & 15) + toHexDigit(b & 15);","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/external/cmapscompress/compress.mjs#L332-L368","documentation":"compress.mjs decodes the binary `.bcmap` format. Each record's high 3 bits (`b >> 5`) form a `type` field; only types 0-5 (range/char mappings) and type 7 (comment/usecmap metadata) are defined by the Adobe CMap binary spec. Hitting the `default` branch means the decoded type is 6 or 8-31, which the format does not define — almost always a sign that the input byte stream is misaligned or the file is not a real bcmap. The reader then cannot continue safely, so it aborts.","triggerScenarios":"Feeding a non-bcmap file (e.g. a plain-text CMap, a gzipped blob, a truncated file) into the bcmap reader; bit-level corruption from a bad git checkout, transfer, or partial write; an endianness/encoding mismatch; reading past EOF so `readByte` returns garbage rather than -1.","commonSituations":"Running `gulp cmaps` after `external/cmaps` was populated with text CMap sources but the binary reader is invoked on the wrong artifact; a corrupted `external/bcmaps` shipped in a dist build; a fork that hand-edited bcmap files.","solutions":["Regenerate the bcmap from source: run `gulp cmaps` so text CMaps in external/cmaps are recompressed fresh.","Verify the input is actually a binary bcmap (starts with the header byte, no UTF-8 BOM, not gzipped) — `file external/bcmaps/<name>.bcmap` and a hexdump of the first bytes.","Re-fetch the file from a trusted source (git checkout / redownload) to rule out transfer corruption.","If you maintain the compressor, audit the byte-writing code: a type value of 6 indicates the high bits were written incorrectly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Cheap header sanity check before invoking the bcmap reader.\nfunction looksLikeBcmap(buf) {\n  return buf && buf.length > 0 && (buf[0] & 0xfe) >>> 1 <= 1; // header type field sanity\n}","typeGuard":"/** @param {unknown} f */\nfunction isBcmapFile(f) {\n  return typeof f === 'string' && f.toLowerCase().endsWith('.bcmap');\n}","tryCatchPattern":"try {\n  result = readBcmap(buf);\n} catch (e) {\n  if (/Unknown type/.test(e.message)) {\n    // regenerate from source rather than trusting the corrupt artifact\n    await runGulp('cmaps');\n    result = readBcmap(fs.readFileSync(path));\n  } else {\n    throw e;\n  }\n}","preventionTips":["Regenerate bcmaps via `gulp cmaps` instead of editing them by hand.","Treat any bcmap that fails to round-trip as corrupt and re-derive from source.","Pin external/bcmaps in git so corruption is caught by diff, not at runtime."],"tags":["cmaps","binary-parsing","data-corruption","build"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}