Skip to content

Commit 7edb627

Browse files
author
Ma Lin
authored
bpo-41735: Fix thread lock in zlib.Decompress.flush() may go wrong (GH-29587)
* Fix thread lock in zlib.Decompress.flush() may go wrong Getting `.unconsumed_tail` before acquiring the thread lock may mix up decompress state.
1 parent 4841e69 commit 7edb627

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix thread lock in ``zlib.Decompress.flush()`` method before ``PyObject_GetBuffer``.

Modules/zlibmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,12 +1269,13 @@ zlib_Decompress_flush_impl(compobject *self, PyTypeObject *cls,
12691269
return NULL;
12701270
}
12711271

1272+
ENTER_ZLIB(self);
1273+
12721274
if (PyObject_GetBuffer(self->unconsumed_tail, &data, PyBUF_SIMPLE) == -1) {
1275+
LEAVE_ZLIB(self);
12731276
return NULL;
12741277
}
12751278

1276-
ENTER_ZLIB(self);
1277-
12781279
self->zst.next_in = data.buf;
12791280
ibuflen = data.len;
12801281

0 commit comments

Comments
 (0)