If the version of zlib used to compile the zlib module is incompatible
with the one that is actually linked in, then calls into zlib will fail.
This can leave attributes of the z_stream uninitialized, so we must take
care to avoid segfaulting by trying to use an invalid pointer.
Fix by Richard M. Tew.
Amy Taylor
Anatoly Techtonik
Mikhail Terekhov
+Richard M. Tew
Tobias Thelen
James Thomas
Robin Thomas
Library
-------
+- Issue #12839: Fix crash in zlib module due to version mismatch.
+ Fix by Richard M. Tew.
+
- Issue #11657: Fix sending file descriptors over 255 over a multiprocessing
Pipe.
static void
zlib_error(z_stream zst, int err, char *msg)
{
- const char *zmsg = zst.msg;
+ const char *zmsg = Z_NULL;
+ /* In case of a version mismatch, zst.msg won't be initialized.
+ Check for this case first, before looking at zst.msg. */
+ if (err == Z_VERSION_ERROR)
+ zmsg = "library version mismatch";
+ if (zmsg == Z_NULL)
+ zmsg = zst.msg;
if (zmsg == Z_NULL) {
switch (err) {
case Z_BUF_ERROR: