From: Ma Lin Date: Sat, 27 Nov 2021 00:21:22 +0000 (+0800) Subject: [3.9] bpo-41735: Fix thread lock in zlib.Decompress.flush() may go wrong (GH-29588) X-Git-Tag: v3.9.10~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86c1265cdc64030c8921e0da5fcae2ac64299c26;p=thirdparty%2FPython%2Fcpython.git [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. --- 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 000000000000..101da0e9ce64 --- /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 8f8bcd85f2c1..4dfd4ae67220 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;