[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 https://github.com/python/cpython/pull/29587 to 3.9/3.8.
This commit is contained in:
Ma Lin 2021-11-27 08:21:22 +08:00 committed by GitHub
parent 133fb267f4
commit 86c1265cdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -0,0 +1 @@
Fix thread lock in ``zlib.Decompress.flush()`` method before ``PyObject_GetBuffer``.

View file

@ -1134,11 +1134,13 @@ zlib_Decompress_flush_impl(compobject *self, Py_ssize_t length)
return NULL;
}
if (PyObject_GetBuffer(self->unconsumed_tail, &data, PyBUF_SIMPLE) == -1)
return NULL;
ENTER_ZLIB(self);
if (PyObject_GetBuffer(self->unconsumed_tail, &data, PyBUF_SIMPLE) == -1) {
LEAVE_ZLIB(self);
return NULL;
}
self->zst.next_in = data.buf;
ibuflen = data.len;