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
b6d2acb1b1
commit
b3a3a811b2
|
@ -0,0 +1 @@
|
||||||
|
Fix thread locks in zlib module may go wrong in rare case. Patch by Ma Lin.
|
|
@ -667,11 +667,11 @@ zlib_Compress_compress_impl(compobject *self, Py_buffer *data)
|
||||||
Py_ssize_t ibuflen, obuflen = DEF_BUF_SIZE;
|
Py_ssize_t ibuflen, obuflen = DEF_BUF_SIZE;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
ENTER_ZLIB(self);
|
||||||
|
|
||||||
self->zst.next_in = data->buf;
|
self->zst.next_in = data->buf;
|
||||||
ibuflen = data->len;
|
ibuflen = data->len;
|
||||||
|
|
||||||
ENTER_ZLIB(self);
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
arrange_input_buffer(&self->zst, &ibuflen);
|
arrange_input_buffer(&self->zst, &ibuflen);
|
||||||
|
|
||||||
|
@ -785,6 +785,8 @@ zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
|
||||||
else
|
else
|
||||||
hard_limit = max_length;
|
hard_limit = max_length;
|
||||||
|
|
||||||
|
ENTER_ZLIB(self);
|
||||||
|
|
||||||
self->zst.next_in = data->buf;
|
self->zst.next_in = data->buf;
|
||||||
ibuflen = data->len;
|
ibuflen = data->len;
|
||||||
|
|
||||||
|
@ -792,8 +794,6 @@ zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
|
||||||
if (max_length && obuflen > max_length)
|
if (max_length && obuflen > max_length)
|
||||||
obuflen = max_length;
|
obuflen = max_length;
|
||||||
|
|
||||||
ENTER_ZLIB(self);
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
arrange_input_buffer(&self->zst, &ibuflen);
|
arrange_input_buffer(&self->zst, &ibuflen);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue