SixLabors/ImageSharp · error · InvalidImageContentException
Invalid EXR image header
Error message
Invalid EXR image header
What it means
Thrown when the EXR decoder reads a header that fails structural validation — required attributes (channels, dataWindow, etc.) are missing, malformed, or the offset table is invalid. It is an InvalidImageContentException, meaning the input bytes do not form a valid EXR header.
Solutions
- Validate the source file with `exrheader` to confirm it is a well-formed EXR
- Re-obtain or re-export the file from the original source
- Check that the stream length is complete (compare against expected file size) before decoding
- If reading from a network stream, ensure the full file was downloaded (checksum)
Example fix
// before
var image = Image.Load(partialStream);
// after
if (stream.CanSeek && stream.Length < 8) throw new InvalidDataException("File too small to be EXR");
var image = Image.Load(stream); // may still throw for malformed headers Defensive patterns
Strategy: try-catch
Validate before calling
// Basic sanity before decode
if (stream.CanSeek && stream.Length < 8) throw new InvalidDataException("Too small to be EXR");
// Optionally verify magic: 0x76 0x2F 0x31 0x01
Try / catch
try { return Image.Load(stream); }
catch (InvalidImageContentException ex) when (ex.Message.Contains("Invalid EXR image header")) { QuarantineAsset(ex); return null; } Prevention
- Verify checksums after download before decoding
- Reject zero-length or suspiciously small files early
- Use ImageSharp's built-in format detection rather than hardcoding the decoder
- Quarantine and log files that fail header validation
When it happens
Trigger: Image.Load/DecodeAsync on bytes whose EXR attribute section ends prematurely, has a zero/invalid terminator, or lacks mandatory attributes; also called with a custom message for specific header violations.
Common situations: Truncated downloads, files renamed to .exr that are actually another format, EXR files written by broken/non-conformant tools, or memory-corrupted buffers.
Related errors
- Gif image does not contain a Logical Screen Descriptor.
- Not supported decoder compression method
- Unsupported EXR version
- Unable to read Gif image data
- Invalid gif colormap size
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/28ef71d924bdcd3d.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Formats/Exr/ExrThrowHelper.cs:26
/// <summary>
/// Cold path optimizations for throwing exr format based exceptions.
/// </summary>
internal static class ExrThrowHelper
{
[DoesNotReturn]
public static Exception NotSupportedDecompressor(string compressionType) => throw new NotSupportedException($"Not supported decoder compression method: {compressionType}");
[DoesNotReturn]
public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);
[DoesNotReturn]
public static void ThrowNotSupportedVersion() => throw new NotSupportedException("Unsupported EXR version");
[DoesNotReturn]
public static void ThrowNotSupported(string msg) => throw new NotSupportedException(msg);
[DoesNotReturn]
public static void ThrowInvalidImageHeader() => throw new InvalidImageContentException("Invalid EXR image header");
[DoesNotReturn]
public static void ThrowInvalidImageHeader(string msg) => throw new InvalidImageContentException(msg);
[DoesNotReturn]
public static Exception NotSupportedCompressor(string compressionType) => throw new NotSupportedException($"Not supported encoder compression method: {compressionType}");
}
View on GitHub (pinned to 59ce6af6fc)