From 0bee1972ede66db2e52849b21effe66bcaf84bc0 Mon Sep 17 00:00:00 2001 From: Ma Lin Date: Tue, 16 Nov 2021 18:12:25 +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-16-18-13-49.bpo-41735.D72UY1.rst | 1 + Modules/zlibmodule.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2021-11-16-18-13-49.bpo-41735.D72UY1.rst 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 00000000000000..88970fbc1d3095 --- /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 may go wrong. diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index 67bde701fa608b..f9646568d7e01d 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; From dd72e4b28b4e9e09861a3e4a2d3ac7f4f72d73ee Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 26 Nov 2021 15:50:09 -0800 Subject: [PATCH 2/2] wording. --- .../next/Library/2021-11-16-18-13-49.bpo-41735.D72UY1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 88970fbc1d3095..101da0e9ce6487 100644 --- 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 @@ -1 +1 @@ -Fix thread lock in zlib.Decompress.flush() method may go wrong. +Fix thread lock in ``zlib.Decompress.flush()`` method before ``PyObject_GetBuffer``.