summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMa Lin <animalize@users.noreply.github.com>2021-04-26 19:48:20 (GMT)
committerGitHub <noreply@github.com>2021-04-26 19:48:20 (GMT)
commit196b8f300479d4e4050d9af9ba4ed82ee1e81dc8 (patch)
tree7672c16e4025f00641fa888fc8c8bcc00c1fcaa8
parentb570feaa9c6039b9d89cdf854a5fb388872eb38e (diff)
downloadcpython-196b8f300479d4e4050d9af9ba4ed82ee1e81dc8.zip
cpython-196b8f300479d4e4050d9af9ba4ed82ee1e81dc8.tar.gz
cpython-196b8f300479d4e4050d9af9ba4ed82ee1e81dc8.tar.bz2
Fix thread locks in zlib module may go wrong in rare case (#22132)
Setting `next_in` before acquiring the thread lock may mix up compress/decompress state in other threads.
-rw-r--r--Misc/NEWS.d/next/Library/2020-09-07-21-51-17.bpo-41735.NKqGKy.rst1
-rw-r--r--Modules/zlibmodule.c8
2 files changed, 5 insertions, 4 deletions
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
index 0000000..9e36435
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-09-07-21-51-17.bpo-41735.NKqGKy.rst
@@ -0,0 +1 @@
+Fix thread locks in zlib module may go wrong in rare case. Patch by Ma Lin.
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index a3d9ed6..d6b6b01 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -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);