{"record":{"id":"28ef71d924bdcd3d","repo":"SixLabors/ImageSharp","slug":"invalid-exr-image-header","errorCode":null,"errorMessage":"Invalid EXR image header","messagePattern":"Invalid EXR image header","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Exr/ExrThrowHelper.cs","lineNumber":26,"sourceCode":"/// <summary>\n/// Cold path optimizations for throwing exr format based exceptions.\n/// </summary>\ninternal static class ExrThrowHelper\n{\n    [DoesNotReturn]\n    public static Exception NotSupportedDecompressor(string compressionType) => throw new NotSupportedException($\"Not supported decoder compression method: {compressionType}\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);\n\n    [DoesNotReturn]\n    public static void ThrowNotSupportedVersion() => throw new NotSupportedException(\"Unsupported EXR version\");\n\n    [DoesNotReturn]\n    public static void ThrowNotSupported(string msg) => throw new NotSupportedException(msg);\n\n    [DoesNotReturn]\n    public static void ThrowInvalidImageHeader() => throw new InvalidImageContentException(\"Invalid EXR image header\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidImageHeader(string msg) => throw new InvalidImageContentException(msg);\n\n    [DoesNotReturn]\n    public static Exception NotSupportedCompressor(string compressionType) => throw new NotSupportedException($\"Not supported encoder compression method: {compressionType}\");\n}\n","sourceCodeStart":8,"sourceCodeEnd":34,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Exr/ExrThrowHelper.cs#L8-L34","documentation":"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.","triggerScenarios":"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.","commonSituations":"Truncated downloads, files renamed to .exr that are actually another format, EXR files written by broken/non-conformant tools, or memory-corrupted buffers.","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)"],"exampleFix":"// before\nvar image = Image.Load(partialStream);\n// after\nif (stream.CanSeek && stream.Length < 8) throw new InvalidDataException(\"File too small to be EXR\");\nvar image = Image.Load(stream); // may still throw for malformed headers","handlingStrategy":"try-catch","validationCode":"// Basic sanity before decode\nif (stream.CanSeek && stream.Length < 8) throw new InvalidDataException(\"Too small to be EXR\");\n// Optionally verify magic: 0x76 0x2F 0x31 0x01\n","typeGuard":null,"tryCatchPattern":"try { return Image.Load(stream); }\ncatch (InvalidImageContentException ex) when (ex.Message.Contains(\"Invalid EXR image header\")) { QuarantineAsset(ex); return null; }","preventionTips":["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"],"tags":["exr","decoder","header","corrupt"],"backgroundTag":"unexpected-response-shape","analyzedSha":"59ce6af6fc29027cda277ef62d4d1694a8acce91","analyzedAt":"2026-09-13T18:34:59.331Z","contentChangedAt":"2026-09-13T18:34:59.331Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}