Right Code, Wrong Comment: The Pointer Chase Inside zlib
Summary
The article analyzes a memory-safety risk in zlib's DEFLATE implementation, showing that a commonly cited 38-line proof does not guarantee safety if a pending buffer is overwritten by the encoding process. It explains the two-pass block encoding, three block formats, and the buffer overlap that could lead to out-of-bounds reads. Using Lean 4 formal verification, the authors map the problem across memLevel regimes and discuss real-world implications and potential upstream fixes.