SixLabors/ImageSharp · error · ImageFormatException
Invalid window size for ZLIB header: cinfo=
Error message
Invalid window size for ZLIB header: cinfo={cinfo} What it means
The ZLIB header's CINFO field encodes the LZ77 window size (2^(CINFO+8)); RFC 1950 only defines values up to 7 (32 KiB). When inflating a critical chunk's ZLIB stream, a CINFO above 7 throws an ImageFormatException; for non-critical chunks the decoder just skips the chunk instead.
Solutions
- Re-encode/re-save the PNG with a standard deflate encoder (zlib window size <= 32 KiB).
- Recover the image bytes from a clean source; treat the file as corrupt.
- Catch ImageFormatException and skip the image or fall back to another decoder.
Defensive patterns
Strategy: try-catch
Validate before calling
// PNG chunk-level header check is not practical pre-call; validate file integrity instead: // verify signature + chunk CRCs with a PNG validator before decoding.
Try / catch
try { using var img = Image.Load(path); }
catch (ImageFormatException ex) when (ex.Message.Contains("ZLIB header"))
{ logger.LogWarning(ex, "Corrupt zlib stream in {Path}", path); } Prevention
- Do not re-compress IDAT payload bytes with non-zlib settings.
- Verify file integrity (checksums) when images travel over lossy channels.
- Treat any ImageFormatException about zlib headers as file corruption, not a config problem.
When it happens
Trigger: Decoding a PNG whose critical chunk (IDAT) carries a ZLIB stream with a corrupt or non-deflate compression method window size, e.g. manually re-compressed or maliciously crafted files.
Common situations: Files rewritten by broken encoders; data truncated/corrupted in transit so the header bytes are garbage; fuzzed or adversarial PNG inputs.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Bad method for ZLIB header: cmf=
- Invalid compressed PNG metadata.
- Unknown filter type.
- The ANI sequence references a missing frame resource.
- The ANI file does not contain any decodable animation steps.
AI-assisted analysis of SixLabors/ImageSharp@59ce6af6fc (2026-09-13).
Data as JSON: /api/errors/a32ee9621b15e8a0.
Report an issue: GitHub.
Appendix: source
Thrown at src/ImageSharp/Compression/Zlib/ZlibInflateReader.cs:87
int cmf = this.segmentStream.ReadByte();
int flag = this.segmentStream.ReadByte();
if (cmf == -1 || flag == -1)
{
return false;
}
if ((cmf & 0x0F) == 8)
{
// CINFO is the base-2 logarithm of the LZ77 window size, minus eight.
int cinfo = (cmf & 0xF0) >> 4;
if (cinfo > 7)
{
if (isCriticalChunk)
{
// Values of CINFO above 7 are not allowed in RFC1950.
// CINFO is not defined in this specification for CM not equal to 8.
throw new ImageFormatException($"Invalid window size for ZLIB header: cinfo={cinfo}");
}
return false;
}
}
else if (isCriticalChunk)
{
throw new ImageFormatException($"Bad method for ZLIB header: cmf={cmf}");
}
else
{
return false;
}
// The preset dictionary.
bool fdict = (flag & 32) != 0;
if (fdict)
{View on GitHub (pinned to 59ce6af6fc)