{"record":{"id":"bad817340bfa1f17","repo":"SixLabors/ImageSharp","slug":"invalid-interlace-method-expected-none-or-adam7-was-this","errorCode":null,"errorMessage":"Invalid interlace method. Expected 'None' or 'Adam7'. Was '{this.InterlaceMethod}'.","messagePattern":"Invalid interlace method\\. Expected 'None' or 'Adam7'\\. Was '(.+?)'\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Formats/Png/Chunks/PngHeader.cs","lineNumber":109,"sourceCode":"        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\n        buffer[8] = this.BitDepth;\n        buffer[9] = (byte)this.ColorType;\n        buffer[10] = this.CompressionMethod;\n        buffer[11] = this.FilterMethod;\n        buffer[12] = (byte)this.InterlaceMethod;\n    }","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Formats/Png/Chunks/PngHeader.cs#L91-L127","documentation":"PngHeader.Validate throws this NotSupportedException when the IHDR interlace method is neither 0 (None) nor 1 (Adam7), the only two methods the PNG specification defines. The library cannot de-interlace an image that uses any other value.","triggerScenarios":"Decoding a PNG whose IHDR InterlaceMethod byte is >= 2 — only possible via non-conformant encoders or corruption of the header bytes.","commonSituations":"Malformed or fuzzed PNG inputs, corrupted files, or files produced by experimental tooling using undefined interlace values.","solutions":["Re-encode the PNG with a standard encoder that sets interlace to None or Adam7.","Verify file integrity and re-download/re-export.","Catch NotSupportedException around Image.Load and handle the invalid file (skip, log, or substitute)."],"exampleFix":"// before\nusing var image = Image.Load(\"broken.png\");\n// after\ntry\n{\n    using var image = Image.Load(\"broken.png\");\n}\ncatch (NotSupportedException ex)\n{\n    Console.WriteLine($\"Non-conformant PNG header: {ex.Message}\");\n}","handlingStrategy":"try-catch","validationCode":"// interlace method byte must be 0 (None) or 1 (Adam7)\nstatic bool IsSupportedInterlace(byte interlaceMethod) => interlaceMethod is 0 or 1;","typeGuard":"static bool IsSupportedInterlace(byte m) => m is 0 or 1;","tryCatchPattern":"try\n{\n    using var image = Image.Load(pngStream);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"interlace method\"))\n{\n    log.LogWarning(\"PNG rejected: {Msg}\", ex.Message);\n}","preventionTips":["Only emit PNGs with interlace set to None or Adam7.","Fuzz-test custom encoders against IHDR validation before shipping.","Quarantine files failing Image.Identify in ingestion pipelines."],"tags":["png","ihdr","interlace","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"}