[Python-checkins] [3.9] bpo-41735: Fix thread lock in zlib.Decompress.flush() may go wrong (GH-29588)

gpshead webhook-mailer at python.org
Fri Nov 26 19:21:31 EST 2021


https://github.com/python/cpython/commit/86c1265cdc64030c8921e0da5fcae2ac64299c26
commit: 86c1265cdc64030c8921e0da5fcae2ac64299c26
branch: 3.9
author: Ma Lin <animalize at users.noreply.github.com>
committer: gpshead <greg at krypto.org>
date: 2021-11-26T16:21:22-08:00
summary:

[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.

files:
A Misc/NEWS.d/next/Library/2021-11-17-11-38-30.bpo-41735.2feh9v.rst
M 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
index 0000000000000..101da0e9ce648
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-11-17-11-38-30.bpo-41735.2feh9v.rst
@@ -0,0 +1 @@
+Fix thread lock in ``zlib.Decompress.flush()`` method before ``PyObject_GetBuffer``.
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 8f8bcd85f2c16..4dfd4ae672200 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -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;
 



More information about the Python-checkins mailing list