]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix thread locks in zlib module may go wrong in rare case (#22132)
authorMa Lin <animalize@users.noreply.github.com>
Mon, 26 Apr 2021 19:48:20 +0000 (03:48 +0800)
committerGitHub <noreply@github.com>
Mon, 26 Apr 2021 19:48:20 +0000 (21:48 +0200)
Setting `next_in` before acquiring the thread lock may mix up compress/decompress state in other threads.

Misc/NEWS.d/next/Library/2020-09-07-21-51-17.bpo-41735.NKqGKy.rst [new file with mode: 0644]
Modules/zlibmodule.c

diff --git a/Misc/NEWS.d/next/Library/2020-09-07-21-51-17.bpo-41735.NKqGKy.rst b/Misc/NEWS.d/next/Library/2020-09-07-21-51-17.bpo-41735.NKqGKy.rst
new file mode 100644 (file)
index 0000000..9e36435
--- /dev/null
@@ -0,0 +1 @@
+Fix thread locks in zlib module may go wrong in rare case. Patch by Ma Lin.
index a3d9ed6646dec8e265e0996689885567249248c7..d6b6b01d89a17490593be6ffa0cf3f4fecdfe792 100644 (file)
@@ -653,11 +653,11 @@ zlib_Compress_compress_impl(compobject *self, Py_buffer *data)
     Py_ssize_t ibuflen, obuflen = DEF_BUF_SIZE;
     int err;
 
+    ENTER_ZLIB(self);
+
     self->zst.next_in = data->buf;
     ibuflen = data->len;
 
-    ENTER_ZLIB(self);
-
     do {
         arrange_input_buffer(&self->zst, &ibuflen);
 
@@ -771,6 +771,8 @@ zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
     else
         hard_limit = max_length;
 
+    ENTER_ZLIB(self);
+
     self->zst.next_in = data->buf;
     ibuflen = data->len;
 
@@ -778,8 +780,6 @@ zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
     if (max_length && obuflen > max_length)
         obuflen = max_length;
 
-    ENTER_ZLIB(self);
-
     do {
         arrange_input_buffer(&self->zst, &ibuflen);