SixLabors/ImageSharp · error · InvalidIccProfileException

Invalid BMP ICC profile.

Error message

Invalid BMP ICC profile.

What it means

When a BMP V5 header carries an embedded ICC profile, the decoder parses it and validates it with CheckIsValid(). If the profile bytes fail validation, it throws InvalidIccProfileException instead of attaching an invalid profile to the image metadata.

Solutions

  1. Re-export the BMP without an embedded ICC profile (V4/V3 header) or with a valid sRGB profile.
  2. Strip or fix the profile data region in the file.
  3. Catch InvalidIccProfileException and decode via a lower-level path or reject the file.

Example fix

// before
using Image img = Image.Load(bmpBytes); // throws on bad ICC
// after
try { using Image img = Image.Load(bmpBytes); }
catch (InvalidIccProfileException) { /* handle file without color management */ }
Defensive patterns

Strategy: try-catch

Validate before calling

// no cheap pre-check available; validate after failure by decoding with a V3/V4-header copy of the file

Try / catch

try { using var img = Image.Load(bmpStream); }
catch (InvalidIccProfileException) { bmpStream.Seek(0, SeekOrigin.Begin); /* decode ignoring color profile or reject */ }

Prevention

When it happens

Trigger: Decoding a BMP with a V5 header whose profileData/profileSize point at bytes that do not form a valid ICC profile (truncated profile, wrong offset, garbage bytes).

Common situations: BMPs written by tools that embed malformed or proprietary color profiles; files edited/truncated after export so the profile region is damaged.

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/6aedcd026ae07a65. Report an issue: GitHub.

Appendix: source

Thrown at src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs:1500

            BmpThrowHelper.ThrowInvalidImageContentException("Not enough data to read BMP ICC profile.");
        }

        byte[] iccProfileData = new byte[this.infoHeader.ProfileSize];
        stream.Position = profileStart;

        if (stream.Read(iccProfileData) != iccProfileData.Length)
        {
            BmpThrowHelper.ThrowInvalidImageContentException("Not enough data to read BMP ICC profile.");
        }

        IccProfile profile = new(iccProfileData);
        if (profile.CheckIsValid())
        {
            imageMetadata.IccProfile = profile;
        }
        else
        {
            throw new InvalidIccProfileException("Invalid BMP ICC profile.");
        }
    }

    /// <summary>
    /// Reads the <see cref="BmpFileHeader"/> from the stream.
    /// </summary>
    /// <param name="stream">The <see cref="BufferedReadStream"/> containing image data.</param>
    private void ReadFileHeader(BufferedReadStream stream)
    {
        Span<byte> buffer = stackalloc byte[BmpFileHeader.Size];
        stream.Read(buffer, 0, BmpFileHeader.Size);

        short fileTypeMarker = BinaryPrimitives.ReadInt16LittleEndian(buffer);
        switch (fileTypeMarker)
        {
            case BmpConstants.TypeMarkers.Bitmap:
                this.fileMarkerType = BmpFileMarkerType.Bitmap;
                this.fileHeader = BmpFileHeader.Parse(buffer);

View on GitHub (pinned to 59ce6af6fc)