SixLabors/ImageSharp · error · InvalidImageContentException
CRC Error. PNG chunk is corrupt!
Error message
CRC Error. PNG {chunkTypeName} chunk is corrupt! What it means
Thrown when the CRC32 checksum of a PNG chunk does not match the chunk's stored CRC value, meaning the chunk's bytes were corrupted or altered after encoding. Each PNG chunk carries a CRC over its type and data; a mismatch indicates the data is not what the encoder wrote, and the spec says decoders should treat it as a corrupted file.
Solutions
- Re-obtain the file from its source and verify integrity (hash or CRC check) before decoding.
- Identify the corrupt chunk from the message and repair it with a PNG repair tool that recomputes CRCs (e.g. pngcheck -f, pngfix).
- Ensure binary-safe transfer (FTP binary mode, no text encoding of image data).
- Catch InvalidImageContentException and treat the file as corrupted, prompting re-upload.
Example fix
// before
byte[] png = File.ReadAllBytes(path);
using var image = Image.Load(png);
// after
byte[] png = File.ReadAllBytes(path);
if (!CrcIsExpected(png)) throw new IOException("File corrupt in transit; re-download");
using var image = Image.Load(png); Defensive patterns
Strategy: validation
Validate before calling
// Verify transfer integrity before decoding
using (var sha = System.Security.Cryptography.SHA256.Create())
{
var hash = sha.ComputeHash(File.ReadAllBytes(path));
if (!hash.AsSpan().SequenceEqual(expectedHash))
throw new IOException("File corrupt: re-download required");
} Try / catch
try
{
using var image = Image.Load(stream);
}
catch (InvalidImageContentException ex) when (ex.Message.StartsWith("CRC Error"))
{
// corrupted chunk — prompt re-upload/re-download
} Prevention
- Verify checksums or hashes for image files after transfer.
- Always use binary-safe transfers (FTP binary mode, no text encoding).
- Repair CRC failures with tools like pngfix instead of manually patching bytes.
When it happens
Trigger: Decoding any PNG where a chunk's CRC check fails — bytes modified in transit, bit rot on disk, chunk data edited without recomputing CRC, or a partially corrupted download.
Common situations: Files transferred in ASCII mode (e.g. FTP text-mode), corrupted attachments, files edited by hex editors or scripts that forgot to update the CRC, failing storage media.
Understand the failure class
Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.
Related errors
- {errorMessage}
- Invalid PNG data.
- Invalid window size for ZLIB header: cinfo=
- Bad method for ZLIB header: cmf=
- Not a valid pass index
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/5c1cbe763e91ddd9.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Formats/Png/PngThrowHelper.cs:39
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);
[DoesNotReturn]
public static void ThrowInvalidChunkCrc(string chunkTypeName) => throw new InvalidImageContentException($"CRC Error. PNG {chunkTypeName} chunk is corrupt!");
[DoesNotReturn]
public static void ThrowInvalidParameter(object value, string message, [CallerArgumentExpression(nameof(value))] string name = "")
=> throw new NotSupportedException($"Invalid {name}. {message}. Was '{value}'.");
[DoesNotReturn]
public static void ThrowInvalidParameter(object value1, object value2, string message, [CallerArgumentExpression(nameof(value1))] string name1 = "", [CallerArgumentExpression(nameof(value2))] string name2 = "")
=> throw new NotSupportedException($"Invalid {name1} or {name2}. {message}. Was '{value1}' and '{value2}'.");
[DoesNotReturn]
public static void ThrowNotSupportedColor() => throw new NotSupportedException("Unsupported PNG color type.");
[DoesNotReturn]
public static void ThrowUnknownFilter() => throw new InvalidImageContentException("Unknown filter type.");
}
View on GitHub (pinned to 59ce6af6fc)