Fix thread locks in zlib module may go wrong in rare case (#22130)

Setting `next_in` before acquiring the thread lock may mix up compress/decompress state in other threads.
This commit is contained in:
Ma Lin 2021-04-27 03:50:33 +08:00 committed by GitHub
parent d0698c676c
commit ba7338a460
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -0,0 +1 @@
Fix thread locks in zlib module may go wrong in rare case. Patch by Ma Lin.

View file

@ -667,11 +667,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);
@ -785,6 +785,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;
@ -792,8 +794,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);