{"record":{"id":"8b0610a3f8774e24","repo":"SixLabors/ImageSharp","slug":"png-image-does-not-contain-a-data-chunk","errorCode":null,"errorMessage":"PNG Image does not contain a data chunk.","messagePattern":"PNG Image does not contain a data chunk\\.","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/PngThrowHelper.cs","lineNumber":18,"sourceCode":"// Copyright (c) Six Labors.\n// Licensed under the Six Labors Split License.\n\nusing System.Diagnostics.CodeAnalysis;\nusing System.Runtime.CompilerServices;\n\nnamespace SixLabors.ImageSharp.Formats.Png;\n\ninternal static class PngThrowHelper\n{\n    [DoesNotReturn]\n    public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);\n\n    [DoesNotReturn]\n    public static void ThrowInvalidHeader() => throw new InvalidImageContentException(\"PNG Image must contain a header chunk and it must be located before any other chunks.\");\n\n    [DoesNotReturn]\n    public static void ThrowNoData() => throw new InvalidImageContentException(\"PNG Image does not contain a data chunk.\");\n\n    [DoesNotReturn]\n    public static void ThrowMissingDefaultData() => throw new InvalidImageContentException(\"APNG Image does not contain a default data chunk.\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidAnimationControl() => throw new InvalidImageContentException(\"APNG Image must contain a acTL chunk and it must be located before any IDAT and fdAT chunks.\");\n\n    [DoesNotReturn]\n    public static void ThrowMissingFrameControl() => throw new InvalidImageContentException(\"One of APNG Image's frames do not have a frame control chunk.\");\n\n    [DoesNotReturn]\n    public static void ThrowMissingPalette() => throw new InvalidImageContentException(\"PNG Image does not contain a palette chunk.\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidChunkType() => throw new InvalidImageContentException(\"Invalid PNG data.\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidChunkType(string message) => throw new InvalidImageContentException(message);","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/PngThrowHelper.cs#L1-L36","documentation":"Thrown during PNG decoding when the stream ends without any IDAT (image data) chunk having been encountered. It is a sentinel guard in a validation helper (ThrowNoData), not tied to a specific corrupt payload: the decoder finished chunk iteration and reached the IEND/end of stream with zero data chunks, so no pixel data exists to reconstruct. The input is a truncated or chunk-stripped file (or not a real PNG at all) that passed the header check but is reported as an InvalidImageContentException.","triggerScenarios":"Decoding a PNG that has IHDR but zero IDAT chunks — e.g. metadata-only files, files truncated right after the header, or encoders that wrote no image data before IEND.","commonSituations":"Interrupted downloads or uploads, streaming decodes where the reader consumed only part of the file, malformed files produced by buggy encoders or image-processing pipelines.","solutions":["Verify the file is complete: it should end with an IEND chunk and contain at least one IDAT chunk.","Re-download or re-export the image and retry the decode.","Check the stream wasn't partially read or copied (compare byte counts / file size).","Catch InvalidImageContentException and treat the input as unusable."],"exampleFix":"// before\nusing var image = Image.Load(downloadedStream);\n// after\nif (downloadedStream.Length < expectedMinSize)\n    throw new InvalidOperationException(\"Download incomplete\");\nusing var image = Image.Load(downloadedStream);","handlingStrategy":"validation","validationCode":"// Ensure the transfer completed: e.g. compare size against source metadata\nif (fileInfo.Length < sourceSize)\n    throw new InvalidOperationException(\"Image download incomplete\");","typeGuard":null,"tryCatchPattern":"try\n{\n    using var image = Image.Load(stream);\n}\ncatch (InvalidImageContentException ex) when (ex.Message.Contains(\"data chunk\"))\n{\n    // no IDAT — file is truncated or metadata-only\n}","preventionTips":["Verify file size/completeness after downloads or copies.","Check for the trailing IEND chunk before decoding.","Retry downloads that abort early rather than decoding partial files."],"tags":["png","idat","missing-chunk","image-decoding"],"backgroundTag":"invalid-image-content","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"}