Skip to content

Commit 86c1265

Browse files
author
Ma Lin
authored
[3.9] bpo-41735: Fix thread lock in zlib.Decompress.flush() may go wrong (GH-29588)
* Fix thread lock in zlib.Decompress.flush() may go wrong Getting `.unconsumed_tail` before acquiring the thread lock may mix up decompress state. backport of #29587 to 3.9/3.8.
1 parent 133fb26 commit 86c1265

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,11 +1134,13 @@ zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length)
11341134
return NULL;
11351135
}
11361136

1137-
if (PyObject_GetBuffer(self->unconsumed_tail, &data, PyBUF_SIMPLE) == -1)
1138-
return NULL;
1139-
11401137
ENTER_ZLIB(self);
11411138

1139+
if (PyObject_GetBuffer(self->unconsumed_tail, &data, PyBUF_SIMPLE) == -1) {
1140+
LEAVE_ZLIB(self);
1141+
return NULL;
1142+
}
1143+
11421144
self->zst.next_in = data.buf;
11431145
ibuflen = data.len;
11441146

0 commit comments

Comments
 (0)