zlib's 38-Line Safety Proof Is Wrong, but No Exploit Fits
Right Code, Wrong Comment: The Pointer Chase Inside Zlib
Inside zlib's deflate, a stripped assertion guards against the output buffer overwriting unread symbols. The authors' 38-line proof that this can't happen is flawed: bounding average symbol cost doesn't prevent a mid-block collision, and a collision would trigger an out-of-bounds read in _dist_code[512]. Yet attempts to craft a crashing input all fail. The investigation builds Lean 4 proofs for zlib and zlib-ng, reducing pointer races to Huffman-tree inequalities and closing memLevel 1–2 algebraically.
Bounding the average cost across all symbols says nothing about a prefix of symbols.