Fix thread locks in zlib module may go wrong in rare case
Setting `next_in` before acquiring the thread lock may mix up compress/decompress state in other threads.
This commit is contained in:
parent
4e581d64b8
commit
378e9ad737
|
@ -0,0 +1 @@
|
|||
Fix thread locks in zlib module may go wrong in rare case. Patch by Ma Lin.
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue