]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-41735: Fix thread lock in zlib.Decompress.flush() may go wrong (GH-29588)
authorMa Lin <animalize@users.noreply.github.com>
Sat, 27 Nov 2021 00:21:22 +0000 (08:21 +0800)
committerGitHub <noreply@github.com>
Sat, 27 Nov 2021 00:21:22 +0000 (16:21 -0800)
* 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.

Misc/NEWS.d/next/Library/2021-11-17-11-38-30.bpo-41735.2feh9v.rst [new file with mode: 0644]
Modules/zlibmodule.c

diff --git a/Misc/NEWS.d/next/Library/2021-11-17-11-38-30.bpo-41735.2feh9v.rst b/Misc/NEWS.d/next/Library/2021-11-17-11-38-30.bpo-41735.2feh9v.rst
new file mode 100644 (file)
index 0000000..101da0e
--- /dev/null
@@ -0,0 +1 @@
+Fix thread lock in ``zlib.Decompress.flush()`` method before ``PyObject_GetBuffer``.
index 8f8bcd85f2c16dad342c514fd89cbcfb8ea93870..4dfd4ae67220021b7f9c3a2a1e710301096e6bc7 100644 (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;