mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
3af68fc77c
commit
e730ae7eff
|
@ -747,7 +747,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…
Reference in New Issue