From d3a3bb94a50b93875d8b881b13f48886c944e08d Mon Sep 17 00:00:00 2001 From: Ma Lin Date: Wed, 17 Nov 2021 11:39:01 +0800 Subject: [PATCH 1/2] Fix thread lock in zlib.Decompress.flush() may go wrong Getting `.unconsumed_tail` before acquiring the thread lock may mix up decompress state. --- .../next/Library/2021-11-17-11-38-30.bpo-41735.2feh9v.rst | 1 + Modules/zlibmodule.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2021-11-17-11-38-30.bpo-41735.2feh9v.rst 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 00000000000000..88970fbc1d3095 --- /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 may go wrong. diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 8f8bcd85f2c16d..4dfd4ae6722002 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; From 0803d3cd6e22fb96078393baa083ffb1c334dea2 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 26 Nov 2021 15:51:45 -0800 Subject: [PATCH 2/2] wording. --- .../next/Library/2021-11-17-11-38-30.bpo-41735.2feh9v.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 88970fbc1d3095..101da0e9ce6487 100644 --- 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 @@ -1 +1 @@ -Fix thread lock in zlib.Decompress.flush() method may go wrong. +Fix thread lock in ``zlib.Decompress.flush()`` method before ``PyObject_GetBuffer``.