Skip to content

Commit ba7338a

Browse files
author
Ma Lin
authored
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.
1 parent d0698c6 commit ba7338a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix thread locks in zlib module may go wrong in rare case. Patch by Ma Lin.

Modules/zlibmodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,11 @@ zlib_Compress_compress_impl(compobject *self, Py_buffer *data)
667667
Py_ssize_t ibuflen, obuflen = DEF_BUF_SIZE;
668668
int err;
669669

670+
ENTER_ZLIB(self);
671+
670672
self->zst.next_in = data->buf;
671673
ibuflen = data->len;
672674

673-
ENTER_ZLIB(self);
674-
675675
do {
676676
arrange_input_buffer(&self->zst, &ibuflen);
677677

@@ -785,15 +785,15 @@ zlib_Decompress_decompress_impl(compobject *self, Py_buffer *data,
785785
else
786786
hard_limit = max_length;
787787

788+
ENTER_ZLIB(self);
789+
788790
self->zst.next_in = data->buf;
789791
ibuflen = data->len;
790792

791793
/* limit amount of data allocated to max_length */
792794
if (max_length && obuflen > max_length)
793795
obuflen = max_length;
794796

795-
ENTER_ZLIB(self);
796-
797797
do {
798798
arrange_input_buffer(&self->zst, &ibuflen);
799799

0 commit comments

Comments
 (0)