{"record":{"id":"1ee8aa3d9d84cc72","repo":"SixLabors/ImageSharp","slug":"invalid-png-data","errorCode":null,"errorMessage":"Invalid PNG data.","messagePattern":"Invalid PNG data\\.","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/PngThrowHelper.cs","lineNumber":33,"sourceCode":"    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);\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","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/PngThrowHelper.cs#L15-L51","documentation":"The parameterless variant is a catch-all for chunk-level data that is structurally invalid but not covered by a more specific message: wrong chunk length, illegal chunk ordering, bad internal layout, or other spec violations inside a chunk. ImageSharp surfaces it simply as \"Invalid PNG data.\"","triggerScenarios":"Decoding any PNG where a chunk's contents or placement violate the PNG spec in a way the decoder detects generically — e.g. invalid chunk sequence, malformed ancillary chunk payload, impossible interlace or filter metadata combinations.","commonSituations":"Hand-crafted or mutated PNGs, fuzzed test files, images produced by low-quality encoders, files corrupted in storage or transit.","solutions":["Locate the offending chunk with pngcheck and fix or re-export the image.","Re-encode the image with a standard encoder (System.Drawing-free tools, ImageSharp itself, pnglib).","If you write PNGs programmatically, validate chunk layout against the PNG specification.","Catch InvalidImageContentException for untrusted-input handling."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    using var image = Image.Load(stream);\n}\ncatch (InvalidImageContentException ex) when (ex.Message == \"Invalid PNG data.\")\n{\n    // generic chunk-structure violation — treat input as corrupt\n}","preventionTips":["Validate external PNG files with pngcheck before processing.","Generate PNGs with well-tested encoders, not hand-rolled chunk writers.","Keep images out of text-mode transfer channels that can corrupt bytes."],"tags":["png","chunk-validation","corrupt-input","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"}