SixLabors/ImageSharp · error · InvalidImageContentException
PNG Image does not contain a data chunk.
Error message
PNG Image does not contain a data chunk.
What it means
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.
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.
Example fix
// before
using var image = Image.Load(downloadedStream);
// after
if (downloadedStream.Length < expectedMinSize)
throw new InvalidOperationException("Download incomplete");
using var image = Image.Load(downloadedStream); Defensive patterns
Strategy: validation
Validate before calling
// Ensure the transfer completed: e.g. compare size against source metadata
if (fileInfo.Length < sourceSize)
throw new InvalidOperationException("Image download incomplete"); Try / catch
try
{
using var image = Image.Load(stream);
}
catch (InvalidImageContentException ex) when (ex.Message.Contains("data chunk"))
{
// no IDAT — file is truncated or metadata-only
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- PNG Image must contain a header chunk and it must be…
- {errorMessage}
- APNG Image does not contain a default data chunk.
- Invalid PNG data.
- {message}
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/8b0610a3f8774e24.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Formats/Png/PngThrowHelper.cs:18
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.Png;
internal static class PngThrowHelper
{
[DoesNotReturn]
public static void ThrowInvalidImageContentException(string errorMessage) => throw new InvalidImageContentException(errorMessage);
[DoesNotReturn]
public static void ThrowInvalidHeader() => throw new InvalidImageContentException("PNG Image must contain a header chunk and it must be located before any other chunks.");
[DoesNotReturn]
public static void ThrowNoData() => throw new InvalidImageContentException("PNG Image does not contain a data chunk.");
[DoesNotReturn]
public static void ThrowMissingDefaultData() => throw new InvalidImageContentException("APNG Image does not contain a default data chunk.");
[DoesNotReturn]
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.");
[DoesNotReturn]
public static void ThrowMissingFrameControl() => throw new InvalidImageContentException("One of APNG Image's frames do not have a frame control chunk.");
[DoesNotReturn]
public static void ThrowMissingPalette() => throw new InvalidImageContentException("PNG Image does not contain a palette chunk.");
[DoesNotReturn]
public static void ThrowInvalidChunkType() => throw new InvalidImageContentException("Invalid PNG data.");
[DoesNotReturn]
public static void ThrowInvalidChunkType(string message) => throw new InvalidImageContentException(message);View on GitHub (pinned to 59ce6af6fc)