Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 524148a

Browse files
committed
Issue #12839: Fix crash in zlib module due to version mismatch.
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.
1 parent d54fa55 commit 524148a

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ Monty Taylor
874874
Amy Taylor
875875
Anatoly Techtonik
876876
Mikhail Terekhov
877+
Richard M. Tew
877878
Tobias Thelen
878879
James Thomas
879880
Robin Thomas

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Core and Builtins
2222
Library
2323
-------
2424

25+
- Issue #12839: Fix crash in zlib module due to version mismatch.
26+
Fix by Richard M. Tew.
27+
2528
- Issue #11657: Fix sending file descriptors over 255 over a multiprocessing
2629
Pipe.
2730

Modules/zlibmodule.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ typedef struct
5252
static void
5353
zlib_error(z_stream zst, int err, char *msg)
5454
{
55-
const char *zmsg = zst.msg;
55+
const char *zmsg = Z_NULL;
56+
/* In case of a version mismatch, zst.msg won't be initialized.
57+
Check for this case first, before looking at zst.msg. */
58+
if (err == Z_VERSION_ERROR)
59+
zmsg = "library version mismatch";
60+
if (zmsg == Z_NULL)
61+
zmsg = zst.msg;
5662
if (zmsg == Z_NULL) {
5763
switch (err) {
5864
case Z_BUF_ERROR:

0 commit comments

Comments
 (0)