{"record":{"id":"760d023bb5dbdf23","repo":"SixLabors/ImageSharp","slug":"invalid-name-message-was-value","errorCode":null,"errorMessage":"Invalid {name}. {message}. Was '{value}'.","messagePattern":"Invalid (.+?)\\. (.+?)\\. Was '(.+?)'\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/PngThrowHelper.cs","lineNumber":43,"sourceCode":"\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":25,"sourceCodeEnd":55,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/PngThrowHelper.cs#L25-L55","documentation":"PngThrowHelper.ThrowInvalidParameter throws NotSupportedException with 'Invalid {name}. {message}. Was {value}.' when a decoded PNG chunk carries a parameter value that is structurally invalid. It is thrown during PNG decode when header/frame-control values violate PNG invariants (e.g. zero dimensions, offsets exceeding image width). The exception name embeds the caller's argument expression and offending value, so it pinpoints exactly which decoded field was bad.","triggerScenarios":"Decoding a PNG whose PngFrameControl has Width <= 0 (FrameControl.cs:107), Height <= 0 (line 112), or XOffset + Width exceeding PngHeader.Width (line 117); these call PngThrowHelper.ThrowInvalidParameter with the offending field value.","commonSituations":"Processing truncated, hand-crafted, or corrupted APNG files; fuzzer-generated PNGs; images produced by encoders that write malformed fcTL/fdAT chunk sequences.","solutions":["Inspect the exception message: it names the invalid parameter (e.g. Width, XOffset) and its value; verify the source PNG file's chunk data with a PNG inspector (pngcheck).","Re-export or re-encode the image with a conformant PNG/APNG encoder to repair the malformed chunk.","If the file comes from an untrusted source, validate/reject it before decode; treat NotSupportedException as 'malformed input', not a library bug.","Upgrade SixLabors.ImageSharp in case newer decoders accept additional edge-case values."],"exampleFix":"// before\nImage.Load(\"animation.apng\"); // throws NotSupportedException: Invalid XOffset... Was '2000'\n// after\ntry\n{\n    Image.Load(\"animation.apng\");\n}\ncatch (NotSupportedException ex)\n{\n    // log and reject the malformed PNG\n    Console.WriteLine($\"Malformed PNG chunk parameter: {ex.Message}\");\n}","handlingStrategy":"try-catch","validationCode":"// Cannot inspect PNG chunks without parsing; at minimum sanity-check the file.\nbyte[] hdr = new byte[33];\nusing (var fs = File.OpenRead(path))\n    if (fs.Read(hdr, 0, hdr.Length) < hdr.Length) throw new InvalidDataException(\"Too short for PNG header chunks.\");\nbool isPng = hdr.AsSpan(0, 8).SequenceEqual(new byte[]{137,80,78,71,13,10,26,10});","typeGuard":null,"tryCatchPattern":"try { using var img = Image.Load(path); }\ncatch (NotSupportedException ex) { LogError(ex, \"Malformed PNG chunk parameter; reject file.\"); }","preventionTips":["Treat NotSupportedException during PNG decode as malformed input, not a library defect.","Validate untrusted images with pngcheck before processing.","Re-encode animations with a conformant APNG encoder.","Log the exception message verbatim — it names the bad field and value."],"tags":["png","image-decoding","malformed-input","not-supported"],"backgroundTag":"invalid-argument-value","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"}