{"record":{"id":"2b6b0bd3f80096b5","repo":"mozilla/pdf.js","slug":"failed-to-create-icc-color-space","errorCode":null,"errorMessage":"Failed to create ICC color space","messagePattern":"Failed to create ICC color space","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/icc_colorspace.js","lineNumber":97,"sourceCode":"        this.#convertPixel = (src, srcOffset) =>\n          qcms_convert_four(\n            this.#transformer,\n            src[srcOffset] * 255,\n            src[srcOffset + 1] * 255,\n            src[srcOffset + 2] * 255,\n            src[srcOffset + 3] * 255\n          );\n        break;\n      default:\n        throw new Error(`Unsupported number of components: ${numComps}`);\n    }\n    this.#transformer = qcms_transformer_from_memory(\n      iccProfile,\n      inType,\n      Intent.Perceptual\n    );\n    if (!this.#transformer) {\n      throw new Error(\"Failed to create ICC color space\");\n    }\n    IccColorSpace.#finalizer ||= new FinalizationRegistry(transformer => {\n      qcms_drop_transformer(transformer);\n    });\n    IccColorSpace.#finalizer.register(this, this.#transformer);\n  }\n\n  getRgbHex(src, srcOffset) {\n    const color = this.#convertPixel(src, srcOffset);\n    return Util.makeHexColor(color >> 16, (color >> 8) & 0xff, color & 0xff);\n  }\n\n  getRgbItem(src, srcOffset, dest, destOffset) {\n    const color = this.#convertPixel(src, srcOffset);\n    dest[destOffset] = color >> 16;\n    dest[destOffset + 1] = (color >> 8) & 0xff;\n    dest[destOffset + 2] = color & 0xff;\n  }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/icc_colorspace.js#L79-L115","documentation":"Thrown when qcms_transformer_from_memory returns a falsy value, meaning QCMS could not build a transformer from the supplied ICC profile bytes. The profile is malformed, unsupported, or its header/channels do not match the requested input DataType.","triggerScenarios":"An ICCBased color space with a truncated, corrupt, or unsupported ICC profile is parsed and qcms_transformer_from_memory(iccProfile, inType, Intent.Perceptual) fails. Reached during rendering of any image, pattern, or fill tagged with that ICCBased space.","commonSituations":"Damaged ICC profiles embedded in PDFs; profiles that are technically valid but use features QCMS does not support (e.g. abstract profiles, deviceN); profiles corrupted by a bad object stream.","solutions":["Re-embed a known-good sRGB/Fogra ICC profile in the source PDF.","Validate the embedded ICC profile with ICC profiling tools (e.g. ICC Profile Inspector) before rendering.","Disable wasm ICC support (useWorkerFetch:false) so pdf.js falls back to a non-ICC path instead of throwing.","Catch the error at render time and skip the offending image/page."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// No public validator; you can pre-validate the ICC profile bytes externally\n// with an ICC inspecting tool. Programmatic stub:\nasync function iccProfileLooksValid(bytes) {\n  return bytes instanceof Uint8Array && bytes.length > 128 &&\n    bytes[36] === 0x61 && bytes[37] === 0x63 && bytes[38] === 0x73 && bytes[39] === 0x6d; // 'acsm' signature offset\n}","typeGuard":"function isPlausibleIccProfile(bytes) {\n  return bytes instanceof Uint8Array && bytes.length >= 128;\n}","tryCatchPattern":"try { await page.render({ canvasContext }).promise; }\ncatch (err) {\n  if (err?.message === 'Failed to create ICC color space') {\n    console.warn('Bad ICC profile; retrying with ICC disabled.');\n    await getDocument({ url, useWorkerFetch: false }).promise; // fallback path\n  } else throw err;\n}","preventionTips":["Embed only validated ICC profiles (verify with ICC Profile Inspector).","Keep a non-ICC rendering fallback by toggling useWorkerFetch off when ICC fails.","Catch 'Failed to create ICC color space' and degrade per-image."],"tags":["pdf","icc","qcms","color-profile","malformed-pdf"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}