{"record":{"id":"5c1cbe763e91ddd9","repo":"SixLabors/ImageSharp","slug":"crc-error-png-chunktypename-chunk-is-corrupt","errorCode":null,"errorMessage":"CRC Error. PNG {chunkTypeName} chunk is corrupt!","messagePattern":"CRC Error\\. PNG (.+?) chunk is corrupt!","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/PngThrowHelper.cs","lineNumber":39,"sourceCode":"    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);\n\n    [DoesNotReturn]\n    public static void ThrowInvalidChunkCrc(string chunkTypeName) => throw new InvalidImageContentException($\"CRC Error. PNG {chunkTypeName} chunk is corrupt!\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidParameter(object value, string message, [CallerArgumentExpression(nameof(value))] string name = \"\")\n        => throw new NotSupportedException($\"Invalid {name}. {message}. Was '{value}'.\");\n\n    [DoesNotReturn]\n    public static void ThrowInvalidParameter(object value1, object value2, string message, [CallerArgumentExpression(nameof(value1))] string name1 = \"\", [CallerArgumentExpression(nameof(value2))] string name2 = \"\")\n        => throw new NotSupportedException($\"Invalid {name1} or {name2}. {message}. Was '{value1}' and '{value2}'.\");\n\n    [DoesNotReturn]\n    public static void ThrowNotSupportedColor() => throw new NotSupportedException(\"Unsupported PNG color type.\");\n\n    [DoesNotReturn]\n    public static void ThrowUnknownFilter() => throw new InvalidImageContentException(\"Unknown filter type.\");\n}\n","sourceCodeStart":21,"sourceCodeEnd":55,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/PngThrowHelper.cs#L21-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nbyte[] png = File.ReadAllBytes(path);\nusing var image = Image.Load(png);\n// after\nbyte[] png = File.ReadAllBytes(path);\nif (!CrcIsExpected(png)) throw new IOException(\"File corrupt in transit; re-download\");\nusing var image = Image.Load(png);","handlingStrategy":"validation","validationCode":"// Verify transfer integrity before decoding\nusing (var sha = System.Security.Cryptography.SHA256.Create())\n{\n    var hash = sha.ComputeHash(File.ReadAllBytes(path));\n    if (!hash.AsSpan().SequenceEqual(expectedHash))\n        throw new IOException(\"File corrupt: re-download required\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    using var image = Image.Load(stream);\n}\ncatch (InvalidImageContentException ex) when (ex.Message.StartsWith(\"CRC Error\"))\n{\n    // corrupted chunk — prompt re-upload/re-download\n}","preventionTips":["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."],"tags":["png","crc","checksum-mismatch","corrupt-input"],"backgroundTag":"checksum-mismatch","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"}