{"record":{"id":"67144a9d83c19aae","repo":"SixLabors/ImageSharp","slug":"invalid-filter-method-expected-0-was-this-filtermethod","errorCode":null,"errorMessage":"Invalid filter method. Expected 0. Was '{this.FilterMethod}'.","messagePattern":"Invalid filter method\\. Expected 0\\. Was '(.+?)'\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/Chunks/PngHeader.cs","lineNumber":103,"sourceCode":"    /// </summary>\n    /// <exception cref=\"NotSupportedException\">\n    /// Thrown if the image does pass validation.\n    /// </exception>\n    public void Validate()\n    {\n        if (!PngConstants.ColorTypes.TryGetValue(this.ColorType, out byte[] supportedBitDepths))\n        {\n            throw new NotSupportedException($\"Invalid or unsupported color type. Was '{this.ColorType}'.\");\n        }\n\n        if (supportedBitDepths.AsSpan().IndexOf(this.BitDepth) == -1)\n        {\n            throw new NotSupportedException($\"Invalid or unsupported bit depth. Was '{this.BitDepth}'.\");\n        }\n\n        if (this.FilterMethod != 0)\n        {\n            throw new NotSupportedException($\"Invalid filter method. Expected 0. Was '{this.FilterMethod}'.\");\n        }\n\n        // The png specification only defines 'None' and 'Adam7' as interlaced methods.\n        if (this.InterlaceMethod is not PngInterlaceMode.None and not PngInterlaceMode.Adam7)\n        {\n            throw new NotSupportedException($\"Invalid interlace method. Expected 'None' or 'Adam7'. Was '{this.InterlaceMethod}'.\");\n        }\n    }\n\n    /// <summary>\n    /// Writes the header to the given buffer.\n    /// </summary>\n    /// <param name=\"buffer\">The buffer to write to.</param>\n    public void WriteTo(Span<byte> buffer)\n    {\n        BinaryPrimitives.WriteInt32BigEndian(buffer[..4], this.Width);\n        BinaryPrimitives.WriteInt32BigEndian(buffer.Slice(4, 4), this.Height);\n","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/Chunks/PngHeader.cs#L85-L121","documentation":"PngHeader.Validate throws this NotSupportedException when the IHDR filter method byte is not 0. The PNG specification currently defines only filter method 0 (adaptive five-tap filtering); any other value means an unknown or future variant the library cannot decode.","triggerScenarios":"Decoding a PNG whose IHDR declares FilterMethod != 0 — produced only by non-standard or experimental encoders, or by corruption of the IHDR bytes.","commonSituations":"Files from proprietary or experimental PNG extensions, deliberate malformed inputs, or memory/disk corruption flipping the filter-method byte.","solutions":["Re-encode the image with a standard PNG encoder (filter method 0).","Check for corruption and re-obtain the file.","Catch NotSupportedException around the decode and fall back to an alternate decoder if one exists for your use case."],"exampleFix":"// before\nusing var image = Image.Load(input);\n// after\ntry\n{\n    using var image = Image.Load(input);\n}\ncatch (NotSupportedException)\n{\n    // non-standard filter method in IHDR; re-export the image with a standard encoder\n}","handlingStrategy":"try-catch","validationCode":"// filter method must be 0 in any decodable PNG\ntypeGuard not needed for byte; pre-check:","typeGuard":"static bool HasStandardFilterMethod(byte filterMethod) => filterMethod == 0;","tryCatchPattern":"try\n{\n    using var image = Image.Load(pngStream);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"filter method\"))\n{\n    // non-standard IHDR; fall back to another decoder or re-encode via external tool\n}","preventionTips":["Treat non-zero IHDR filter-method values as corrupt/proprietary inputs and route them to quarantine.","Prefer re-encoding images with ImageSharp or a mainstream tool rather than preserving exotic headers."],"tags":["png","ihdr","filter-method","invalid-header"],"backgroundTag":"unsupported-enum-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"}