{"record":{"id":"a32ee9621b15e8a0","repo":"SixLabors/ImageSharp","slug":"invalid-window-size-for-zlib-header-cinfo-cinfo","errorCode":null,"errorMessage":"Invalid window size for ZLIB header: cinfo={cinfo}","messagePattern":"Invalid window size for ZLIB header: cinfo=(.+?)","errorType":"exception","errorClass":"ImageFormatException","httpStatus":null,"severity":"error","filePath":"src/ImageSharp/Compression/Zlib/ZlibInflateReader.cs","lineNumber":87,"sourceCode":"        int cmf = this.segmentStream.ReadByte();\n        int flag = this.segmentStream.ReadByte();\n        if (cmf == -1 || flag == -1)\n        {\n            return false;\n        }\n\n        if ((cmf & 0x0F) == 8)\n        {\n            // CINFO is the base-2 logarithm of the LZ77 window size, minus eight.\n            int cinfo = (cmf & 0xF0) >> 4;\n\n            if (cinfo > 7)\n            {\n                if (isCriticalChunk)\n                {\n                    // Values of CINFO above 7 are not allowed in RFC1950.\n                    // CINFO is not defined in this specification for CM not equal to 8.\n                    throw new ImageFormatException($\"Invalid window size for ZLIB header: cinfo={cinfo}\");\n                }\n\n                return false;\n            }\n        }\n        else if (isCriticalChunk)\n        {\n            throw new ImageFormatException($\"Bad method for ZLIB header: cmf={cmf}\");\n        }\n        else\n        {\n            return false;\n        }\n\n        // The preset dictionary.\n        bool fdict = (flag & 32) != 0;\n        if (fdict)\n        {","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/SixLabors/ImageSharp/blob/59ce6af6fc29027cda277ef62d4d1694a8acce91/src/ImageSharp/Compression/Zlib/ZlibInflateReader.cs#L69-L105","documentation":"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.","triggerScenarios":"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.","commonSituations":"Files rewritten by broken encoders; data truncated/corrupted in transit so the header bytes are garbage; fuzzed or adversarial PNG inputs.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// PNG chunk-level header check is not practical pre-call; validate file integrity instead:\n// verify signature + chunk CRCs with a PNG validator before decoding.","typeGuard":null,"tryCatchPattern":"try { using var img = Image.Load(path); }\ncatch (ImageFormatException ex) when (ex.Message.Contains(\"ZLIB header\"))\n{ logger.LogWarning(ex, \"Corrupt zlib stream in {Path}\", path); }","preventionTips":["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."],"tags":["zlib","png","corrupt-file","compression"],"backgroundTag":"invalid-config-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"}