Skip to content

SixLabors.ImageSharp.ImageFormatException: Bad method for ZLIB header: cmf=3 after updating to 3.1.8 #2924

@MZole

Description

@MZole

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.1.8

Other ImageSharp packages and versions

SixLabors.ImageSharp

Environment (Operating system, version and so on)

Windows/Linux

.NET Framework version

.NET 8

Description

Dear SixLabors/ImageSharp team, I have encountered the SixLabors.ImageSharp.ImageFormatException: Bad method for ZLIB header: cmf=3 exception upon updating the SixLabors.ImageSharp package to 3.1.8 from 3.1.7.

We are using ImageSharp with automated UI testing to visually verify webpages, hence the odd image. (I promise it's not an advertisement 😄)

I'm attaching the image that raised this error, and I tested this; the image works with 3.1.7, but doesn't with the newest version, both on Windows and Linux.
The code that raises the exception is using var image = Image.Load(imagePath);.

Here is the relevant stacktrace:

2025-05-21 11:04:14.5245 - The test failed with the following exception: SixLabors.ImageSharp.ImageFormatException: Bad method for ZLIB header: cmf=3
   at SixLabors.ImageSharp.Compression.Zlib.ZlibInflateStream.InitializeInflateStream(Boolean isCriticalChunk)
   at SixLabors.ImageSharp.Compression.Zlib.ZlibInflateStream.AllocateNewBytes(Int32 bytes, Boolean isCriticalChunk)
   at SixLabors.ImageSharp.Formats.Png.PngDecoderCore.ReadScanlines[TPixel](Int32 chunkLength, ImageFrame`1 image, PngMetadata pngMetadata, Func`1 getData, FrameControl& frameControl, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Png.PngDecoderCore.Decode[TPixel](BufferedReadStream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoderCore.Decode[TPixel](Configuration configuration, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Png.PngDecoder.Decode[TPixel](PngDecoderOptions options, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.Png.PngDecoder.Decode(PngDecoderOptions options, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.SpecializedImageDecoder`1.Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken)
   at SixLabors.ImageSharp.Formats.ImageDecoder.<>c__DisplayClass1_0.<Decode>b__0(Stream s)
   at SixLabors.ImageSharp.Formats.ImageDecoder.<WithSeekableStream>g__PerformActionAndResetPosition|11_0[T](Stream s, Int64 position, <>c__DisplayClass11_0`1&)
   at SixLabors.ImageSharp.Formats.ImageDecoder.WithSeekableStream[T](DecoderOptions options, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Formats.ImageDecoder.Decode(DecoderOptions options, Stream stream)
   at SixLabors.ImageSharp.Image.Decode(DecoderOptions options, Stream stream)
   at SixLabors.ImageSharp.Image.<>c__DisplayClass80_0.<Load>b__0(Stream s)
   at SixLabors.ImageSharp.Image.WithSeekableStream[T](DecoderOptions options, Stream stream, Func`2 action)
   at SixLabors.ImageSharp.Image.Load(DecoderOptions options, Stream stream)
   at SixLabors.ImageSharp.Image.Load(DecoderOptions options, String path)
   at SixLabors.ImageSharp.Image.Load(String path)

Steps to Reproduce

Repro code:

var imagePath = "path/FailedScreenshot.png";
using var image = Image.Load(imagePath);

Images

Image

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions