New submission from Ma Lin <[email protected]>:
The code in zlib module:
self->zst.next_in = data->buf; // set next_in
...
ENTER_ZLIB(self); // acquire thread lock
`self->zst` is a `z_stream` struct defined in zlib, used to record states of a
compress/decompress stream:
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total number of input bytes read so far */
Bytef *next_out; /* next output byte will go here */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total number of bytes output so far */
... // Other states
} z_stream;
Setting `next_in` before acquiring the thread lock may mix up
compress/decompress state in other threads.
Moreover, modify `ENTER_ZLIB` macro, don't release the GIL when the thread lock
can be acquired immediately. This behavior is the same as the bz2/lzma modules.
----------
components: Library (Lib)
messages: 376473
nosy: malin
priority: normal
severity: normal
status: open
title: Thread locks in zlib module may go wrong in rare case
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41735>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com