Commit 71747d1 for zlib
commit 71747d1d39168833e0cae8ed84b8ce77cb049699
Author: ronald.eytchison@trailofbits.com <ronald.eytchison@trailofbits.com>
Date: Wed Jun 3 21:43:47 2026 +0000
Clarify inflateGetHeader header reuse.
inflateGetHeader() sets extra_len to the full length of the extra
field even when it was truncated to extra_max, and leaves a
truncated name or comment without a terminating zero. A truncated
header cannot be passed to deflateSetHeader() as is.
Reported by Trail of Bits (TOB-ZLIB-002).
diff --git a/zlib.h b/zlib.h
index cc486cb..b6de239 100644
--- a/zlib.h
+++ b/zlib.h
@@ -1099,9 +1099,10 @@ ZEXTERN int ZEXPORT inflateGetHeader(z_streamp strm,
a terminating zero. If any of extra, name, or comment are not present in
the header, then that field's pointer is set to Z_NULL. This allows the use
of deflateSetHeader() with the returned structure to duplicate the header.
- Note that if those fields initially pointed to allocated memory, then the
- application will need to save them elsewhere so that they can be eventually
- freed.
+ Though take care that none of the fields were truncated before so using it,
+ lest havoc ensue. Note that if those fields initially pointed to allocated
+ memory, then the application will need to save them elsewhere so that they
+ can be eventually freed.
If inflateGetHeader is not used, then the header information is simply
discarded. The header is always checked for validity, including the header