SixLabors/ImageSharp · error · InvalidIccProfileException

Read signature is not the expected

Error message

Read signature {type} is not the expected {expected}

What it means

ReadCheckTagDataEntryHeader reads a tag's type signature and compares it against the caller's expected signature. A mismatch means the tag data does not match the structure the caller is about to decode, which would otherwise cause misinterpretation of bytes, so the reader fails fast. (The check is skipped when expected is set to (IccTypeSignature)uint.MaxValue.)

Solutions

  1. Use a valid ICC profile - regenerate or re-export from the source tool.
  2. Verify tag table offsets with an ICC validation tool before loading.
  3. Catch InvalidIccProfileException around profile parsing to handle bad third-party profiles gracefully.
  4. Do not manually patch profile bytes; use a profile editor.

Example fix

// wrap profile loading
try
{
    IccProfile profile = IccReader.Read(stream);
}
catch (InvalidIccProfileException ex)
{
    // log and treat the profile as unusable
    throw new InvalidDataException("Corrupt ICC profile", ex);
}
Defensive patterns

Strategy: try-catch

Try / catch

try
{
    var profile = IccReader.Read(stream);
}
catch (InvalidIccProfileException ex)
{
    throw new InvalidDataException($"ICC tag signature mismatch - profile corrupt: {ex.Message}", ex);
}

Prevention

When it happens

Trigger: Reading a tag data entry via ReadProfileSequenceIdentifierTagDataEntry (and similar checked readers) where the embedded signature is not the expected one - e.g. the tag table points a profileSequenceIdentifierTag at data that is not a profileSequenceDesc-style structure, or bytes are corrupt.

Common situations: Profiles whose tag table entries are misaligned (offset/size errors from bad generators); corrupt or fuzzed profile files; mixing up tag data when manually editing profiles.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs:85

    /// </summary>
    /// <returns>The read signature.</returns>
    public IccTypeSignature ReadTagDataEntryHeader()
    {
        IccTypeSignature type = (IccTypeSignature)this.ReadUInt32();
        this.AddIndex(4); // 4 bytes are not used
        return type;
    }

    /// <summary>
    /// Reads the header of a <see cref="IccTagDataEntry"/> and checks if it's the expected value
    /// </summary>
    /// <param name="expected">The expected value to check against.</param>
    public void ReadCheckTagDataEntryHeader(IccTypeSignature expected)
    {
        IccTypeSignature type = this.ReadTagDataEntryHeader();
        if (expected != (IccTypeSignature)uint.MaxValue && type != expected)
        {
            throw new InvalidIccProfileException($"Read signature {type} is not the expected {expected}");
        }
    }

    /// <summary>
    /// Reads a <see cref="IccTagDataEntry"/> with an unknown <see cref="IccTypeSignature"/>
    /// </summary>
    /// <param name="size">The size of the entry in bytes.</param>
    /// <returns>The read entry.</returns>
    public IccUnknownTagDataEntry ReadUnknownTagDataEntry(uint size)
    {
        int count = (int)size - 8;  // 8 is the tag header size
        return new IccUnknownTagDataEntry(this.ReadBytes(count));
    }

    /// <summary>
    /// Reads a <see cref="IccChromaticityTagDataEntry"/>
    /// </summary>
    /// <returns>The read entry.</returns>

View on GitHub (pinned to 59ce6af6fc)