SixLabors/ImageSharp · error · InvalidIccProfileException

Invalid ICC profile.

Error message

Invalid ICC profile.

What it means

WebpChunkParsingUtils.ReadIccProfile throws InvalidIccProfileException when an ICCP chunk is present but the embedded ICC profile fails IccProfile.CheckIsValid(). The profile bytes were read fine, but they do not form a structurally valid ICC profile, so the decoder refuses to attach it to the image metadata.

Solutions

  1. Strip or repair the ICC profile: re-encode the file without ICCP (e.g. cwebp -no-icc or re-save with a valid profile).
  2. Assign a known-good ICC profile after decoding instead of relying on the embedded one.
  3. Catch InvalidIccProfileException and fall back to decoding while ignoring metadata.
  4. Verify the profile with a validator (e.g. ICC profile inspection tools) to confirm corruption.

Example fix

// before
using var image = Image.Load(stream); // throws on bad ICCP
// after
var dec = new WebpDecoder(); // or:
try { using var image = Image.Load(stream); }
catch (InvalidIccProfileException) { /* decode with metadata ignored or re-source the file */ }
Defensive patterns

Strategy: fallback

Try / catch

try { using var image = Image.Load(stream); return image; }
catch (InvalidIccProfileException) { /* retry ignoring metadata / re-encode without ICCP */ return DecodeIgnoringMetadata(stream); }

Prevention

When it happens

Trigger: Decoding a WebP whose ICCP chunk contains malformed or non-ICC data — profile header size/signature checks fail inside CheckIsValid, typically while metadata is being loaded (ignoreMetadata=false and no existing profile).

Common situations: Files produced by encoders that wrote garbage or truncated color profiles; hand-assembled ICCP chunks; profiles stripped/converted by middleware; exotic color-management pipelines.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13). Data as JSON: /api/errors/5356dcd54b15d8e6. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs:397

    {
        ulong chunkSize = ReadPaddedChunkSize(stream, stackalloc byte[4], true);

        // ICCP precedes image/frame data. Its framing must be readable even when
        // metadata is skipped; otherwise there is no safe location to resume decoding.
        if (!stream.IsReadRangeValid(stream.Position, chunkSize))
        {
            WebpThrowHelper.ThrowInvalidImageContentException("Not enough data to read the ICCP chunk.");
        }

        executeAncillarySegmentAction(() =>
        {
            byte[]? iccpData = ReadMetadataChunk(stream, chunkSize, ignoreMetadata || metadata.IccProfile != null);
            if (iccpData is not null)
            {
                IccProfile profile = new(iccpData);
                if (!profile.CheckIsValid())
                {
                    throw new InvalidIccProfileException("Invalid ICC profile.");
                }

                metadata.IccProfile = profile;
            }
        });
    }

    /// <summary>
    /// Reads the EXIF profile from the stream.
    /// </summary>
    /// <param name="stream">The stream to decode from.</param>
    /// <param name="metadata">The image metadata.</param>
    /// <param name="ignoreMetadata">If true, metadata will be ignored.</param>
    public static void ReadExifProfile(
        BufferedReadStream stream,
        ImageMetadata metadata,
        bool ignoreMetadata)
    {

View on GitHub (pinned to 59ce6af6fc)