{"record":{"id":"aa8804970a2b58fa","repo":"SixLabors/ImageSharp","slug":"unable-to-read-gif-image-data","errorCode":null,"errorMessage":"Unable to read Gif image data","messagePattern":"Unable to read Gif image data","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Gif/GifThrowHelper.cs","lineNumber":18,"sourceCode":"// Copyright (c) Six Labors.\n// Licensed under the Six Labors Split License.\n\nusing System.Diagnostics.CodeAnalysis;\n\nnamespace SixLabors.ImageSharp.Formats.Gif;\n\ninternal static class GifThrowHelper\n{\n    [DoesNotReturn]\n    public static void ThrowInvalidImageContentException(string errorMessage)\n        => throw new InvalidImageContentException(errorMessage);\n\n    [DoesNotReturn]\n    public static void ThrowNoHeader() => throw new InvalidImageContentException(\"Gif image does not contain a Logical Screen Descriptor.\");\n\n    [DoesNotReturn]\n    public static void ThrowNoData() => throw new InvalidImageContentException(\"Unable to read Gif image data\");\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Gif/GifThrowHelper.cs#L1-L20","documentation":"Thrown when a GIF signature was recognized but no image data follows — the decoder found a header yet no Image Descriptor or blocks. Raised as InvalidImageContentException to report that the GIF body is empty.","triggerScenarios":"Image.Load/Decode on a file that begins with a valid GIF header+screen descriptor but ends (or contains only extensions) before any image data block.","commonSituations":"Empty/placeholder GIFs created by buggy tools, files truncated right after the header, or assets uploaded as 0-image GIFs from a broken pipeline.","solutions":["Regenerate the GIF ensuring at least one image block is written","Check the producing pipeline — an empty animation export commonly causes this","Validate minimum file size / presence of an image descriptor before decoding","Catch InvalidImageContentException and treat the asset as invalid in your ingest pipeline"],"exampleFix":"// before\nvar image = Image.Load(stream);\n// after\ntry { var image = Image.Load(stream); }\ncatch (InvalidImageContentException ex) when (ex.Message.Contains(\"image data\")) { MarkAssetInvalid(assetId); }","handlingStrategy":"try-catch","validationCode":"// Ensure the GIF has at least one image descriptor (0x2C) after the header\nbyte[] all = File.ReadAllBytes(path);\nbool hasImageBlock = all.AsSpan(13).IndexOf((byte)0x2C) >= 0;\nif (!hasImageBlock) throw new InvalidDataException(\"GIF contains no image data\");\n","typeGuard":null,"tryCatchPattern":"try { return Image.Load(stream); }\ncatch (InvalidImageContentException ex) when (ex.Message.Contains(\"Unable to read Gif image data\")) { return RegenerateOrSkip(stream); }","preventionTips":["Reject 0-frame GIFs at export time in your pipeline","Validate GIFs with magick identify during ingest","Regenerate placeholder GIFs that contain only extensions","Keep the generating toolchain updated"],"tags":["gif","decoder","empty","corrupt"],"backgroundTag":"empty-result-set","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"}