{"record":{"id":"a5ef73fc052e51b1","repo":"SixLabors/ImageSharp","slug":"message-pngthrowhelper","errorCode":null,"errorMessage":"{message}","messagePattern":"\\{message\\}","errorType":"exception","errorClass":"InvalidImageContentException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/PngThrowHelper.cs","lineNumber":36,"sourceCode":"    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\n    [DoesNotReturn]\n    public static void ThrowUnknownFilter() => throw new InvalidImageContentException(\"Unknown filter type.\");\n}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/PngThrowHelper.cs#L18-L54","documentation":"The string-overload of ThrowInvalidChunkType lets individual decoder call sites raise InvalidImageContentException with a chunk-specific message describing exactly which part of the PNG data was invalid. The thrown message is passed through verbatim, so it pinpoints the failing structure.","triggerScenarios":"Decoding a PNG where a specific chunk fails detailed validation and the decoder supplies a tailored message, e.g. bad bit-depth/color-type combination in IHDR, invalid interlace flag, or malformed chunk-specific payloads.","commonSituations":"Files with IHDR fields outside the allowed combinations (e.g. bit depth 3), corrupt ancillary chunks, images generated by non-conformant encoders, deliberately mutated test files.","solutions":["Read the exception message to identify which chunk/field is invalid, then correct it in the source file.","Re-export the image from the original source with a standard encoder.","Validate the file with pngcheck to get a spec-level diagnosis.","Catch InvalidImageContentException to gracefully reject malformed uploads."],"exampleFix":"// before\nvar ihdr = new IhdrChunk { BitDepth = 3, ColorType = PngColorType.Rgb };\n// after\nvar ihdr = new IhdrChunk { BitDepth = 8, ColorType = PngColorType.Rgb }; // valid combination","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    using var image = Image.Load(stream);\n}\ncatch (InvalidImageContentException ex)\n{\n    // ex.Message pinpoints the invalid chunk/field — log it for diagnosis\n    logger.LogWarning(\"Invalid PNG chunk: {Message}\", ex.Message);\n}","preventionTips":["Check IHDR bit-depth/color-type combinations against the PNG spec when generating images.","Re-export images from the original source instead of patching bytes.","Run pngcheck to get spec-level diagnostics on failing files."],"tags":["png","chunk-validation","invalid-metadata","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"}