Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[3.9] bpo-41735: Fix thread lock in zlib.Decompress.flush() may go wr…
…ong (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.
  • Loading branch information
animalize committed Nov 27, 2021
1 parent 133fb26 commit 86c1265
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
@@ -0,0 +1 @@
Fix thread lock in ``zlib.Decompress.flush()`` method before ``PyObject_GetBuffer``.
8 changes: 5 additions & 3 deletions Modules/zlibmodule.c
Expand Up @@ -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;

Expand Down

0 comments on commit 86c1265

Please sign in to comment.