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.
This commit is contained in:
Ma Lin 2021-11-27 08:18:17 +08:00 committed by GitHub
parent 4841e694ee
commit 7edb6270a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

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

View File

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