SixLabors/ImageSharp · error · InvalidIccProfileException

The CLUT data is shorter than its declared dimensions.

Error message

The CLUT data is shorter than its declared dimensions.

What it means

After computing the expected CLUT size (gridLength * outputChannels * bytesPerValue), the reader checks that enough bytes actually remain in the tag data. If the declared dimensions imply more data than the buffer holds, the profile is declared invalid rather than being partially parsed.

Solutions

  1. Re-obtain a complete, uncorrupted copy of the ICC profile.
  2. Validate tag table offsets and lengths against the file size before parsing.
  3. Catch InvalidIccProfileException and fall back to a non-CLUT rendering intent or a default profile.

Example fix

// before: parse regardless of integrity
var profile = new IccProfile(truncatedBytes);

// after: degrade gracefully on corrupt CLUT data
try
{
    var profile = new IccProfile(truncatedBytes);
}
catch (InvalidIccProfileException ex) when (ex.Message.Contains("CLUT"))
{
    profile = IccProfile.Default; // or disable color management
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Basic integrity check before parsing
if (bytes.Length < headerSize + declaredTagTableSize)
    throw new InvalidDataException("ICC profile is truncated");

Try / catch

try
{
    var profile = new IccProfile(bytes);
}
catch (InvalidIccProfileException ex) when (ex.Message.Contains("shorter than"))
{
    // profile data truncated; use fallback transform
    return ColorManagementFallback;
}

Prevention

When it happens

Trigger: Reading a lutAtoB/lutBToA/lut16 tag whose CLUT header declares grid dimensions and channel counts whose implied byte count exceeds the remaining tag data length; truncated profile files.

Common situations: Truncated ICC profiles (incomplete downloads, sliced files); profiles whose tag offsets/lengths disagree with actual tag data; corrupt binaries.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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

Appendix: source

Thrown at src/ImageSharp/Metadata/Profiles/ICC/DataReader/IccDataReader.Lut.cs:164

    private int GetClutLength(int inputChannelCount, int outputChannelCount, byte[] gridPointCount, int bytesPerValue)
    {
        int length = 1;
        for (int i = 0; i < inputChannelCount; i++)
        {
            int gridPoints = gridPointCount[i];
            if (gridPoints == 0 || length > int.MaxValue / gridPoints)
            {
                throw new InvalidIccProfileException("Invalid CLUT dimensions.");
            }

            length *= gridPoints;
        }

        long valueCount = (long)length * outputChannelCount;
        long byteCount = valueCount * bytesPerValue;
        if (valueCount > int.MaxValue || byteCount > this.data.Length - this.currentIndex)
        {
            throw new InvalidIccProfileException("The CLUT data is shorter than its declared dimensions.");
        }

        return length;
    }
}

View on GitHub (pinned to 59ce6af6fc)