mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
bpo-42369: Fix thread safety of zipfile._SharedFile.tell (GH-26974)
The `_SharedFile` tracks its own virtual position into the file as
`self._pos` and updates it after reading or seeking. `tell()` should
return this position instead of calling into the underlying file object,
since if multiple `_SharedFile` instances are being used concurrently on
the same file, another one may have moved the real file position.
Additionally, calling into the underlying `tell` may expose thread
safety issues in the underlying file object because it was called
without taking the lock.
(cherry picked from commit e730ae7eff
)
Co-authored-by: Kevin Mehall <km@kevinmehall.net>
This commit is contained in:
parent
87b3e202d4
commit
4352ca234e
2 changed files with 4 additions and 1 deletions
|
@ -721,7 +721,9 @@ class _SharedFile:
|
|||
self._lock = lock
|
||||
self._writing = writing
|
||||
self.seekable = file.seekable
|
||||
self.tell = file.tell
|
||||
|
||||
def tell(self):
|
||||
return self._pos
|
||||
|
||||
def seek(self, offset, whence=0):
|
||||
with self._lock:
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix thread safety of :meth:`zipfile._SharedFile.tell` to avoid a "zipfile.BadZipFile: Bad CRC-32 for file" exception when reading a :class:`ZipFile` from multiple threads.
|
Loading…
Add table
Add a link
Reference in a new issue