]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41735: Fix thread lock in zlib.Decompress.flush() may go wrong (GH-29587)
authorMa Lin <animalize@users.noreply.github.com>
Sat, 27 Nov 2021 00:18:17 +0000 (08:18 +0800)
committerGitHub <noreply@github.com>
Sat, 27 Nov 2021 00:18:17 +0000 (16:18 -0800)
* Fix thread lock in zlib.Decompress.flush() may go wrong

Getting `.unconsumed_tail` before acquiring the thread lock may mix up decompress state.

Misc/NEWS.d/next/Library/2021-11-16-18-13-49.bpo-41735.D72UY1.rst [new file with mode: 0644]
Modules/zlibmodule.c

diff --git a/Misc/NEWS.d/next/Library/2021-11-16-18-13-49.bpo-41735.D72UY1.rst b/Misc/NEWS.d/next/Library/2021-11-16-18-13-49.bpo-41735.D72UY1.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 67bde701fa608bd217391a0a9b6d0159bfc50396..f9646568d7e01d4605a79030306d274420eade3b 100644 (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;