Setting `next_in` before acquiring the thread lock may mix up compress/decompress state in other threads.
--- /dev/null
+Fix thread locks in zlib module may go wrong in rare case. Patch by Ma Lin.
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);
else
hard_limit = max_length;
+ ENTER_ZLIB(self);
+
self->zst.next_in = data->buf;
ibuflen = data->len;
if (max_length && obuflen > max_length)
obuflen = max_length;
- ENTER_ZLIB(self);
-
do {
arrange_input_buffer(&self->zst, &ibuflen);