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

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


https://github.com/python/cpython/commit/7edb6270a78c695e4c2ae2432797dc18105374fc
commit: 7edb6270a78c695e4c2ae2432797dc18105374fc
branch: main
author: Ma Lin <animalize at users.noreply.github.com>
committer: gpshead <greg at krypto.org>
date: 2021-11-26T16:18:17-08:00
summary:

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.

files:
A Misc/NEWS.d/next/Library/2021-11-16-18-13-49.bpo-41735.D72UY1.rst
M 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
index 0000000000000..101da0e9ce648
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-11-16-18-13-49.bpo-41735.D72UY1.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 67bde701fa608..f9646568d7e01 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -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;
 



More information about the Python-checkins mailing list