mozilla/pdf.js · error · Error

Failed to create ICC color space

Error message

Failed to create ICC color space

What it means

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.

Source

Thrown at src/core/icc_colorspace.js:97

        this.#convertPixel = (src, srcOffset) =>
          qcms_convert_four(
            this.#transformer,
            src[srcOffset] * 255,
            src[srcOffset + 1] * 255,
            src[srcOffset + 2] * 255,
            src[srcOffset + 3] * 255
          );
        break;
      default:
        throw new Error(`Unsupported number of components: ${numComps}`);
    }
    this.#transformer = qcms_transformer_from_memory(
      iccProfile,
      inType,
      Intent.Perceptual
    );
    if (!this.#transformer) {
      throw new Error("Failed to create ICC color space");
    }
    IccColorSpace.#finalizer ||= new FinalizationRegistry(transformer => {
      qcms_drop_transformer(transformer);
    });
    IccColorSpace.#finalizer.register(this, this.#transformer);
  }

  getRgbHex(src, srcOffset) {
    const color = this.#convertPixel(src, srcOffset);
    return Util.makeHexColor(color >> 16, (color >> 8) & 0xff, color & 0xff);
  }

  getRgbItem(src, srcOffset, dest, destOffset) {
    const color = this.#convertPixel(src, srcOffset);
    dest[destOffset] = color >> 16;
    dest[destOffset + 1] = (color >> 8) & 0xff;
    dest[destOffset + 2] = color & 0xff;
  }

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Re-embed a known-good sRGB/Fogra ICC profile in the source PDF.
  2. Validate the embedded ICC profile with ICC profiling tools (e.g. ICC Profile Inspector) before rendering.
  3. Disable wasm ICC support (useWorkerFetch:false) so pdf.js falls back to a non-ICC path instead of throwing.
  4. Catch the error at render time and skip the offending image/page.
Defensive patterns

Strategy: fallback

Validate before calling

// No public validator; you can pre-validate the ICC profile bytes externally
// with an ICC inspecting tool. Programmatic stub:
async function iccProfileLooksValid(bytes) {
  return bytes instanceof Uint8Array && bytes.length > 128 &&
    bytes[36] === 0x61 && bytes[37] === 0x63 && bytes[38] === 0x73 && bytes[39] === 0x6d; // 'acsm' signature offset
}

Type guard

function isPlausibleIccProfile(bytes) {
  return bytes instanceof Uint8Array && bytes.length >= 128;
}

Try / catch

try { await page.render({ canvasContext }).promise; }
catch (err) {
  if (err?.message === 'Failed to create ICC color space') {
    console.warn('Bad ICC profile; retrying with ICC disabled.');
    await getDocument({ url, useWorkerFetch: false }).promise; // fallback path
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/2b6b0bd3f80096b5. Report an issue: GitHub.