diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-03-20 14:51:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-20 14:51:11 (GMT) |
commit | 4352ca234e979ad1c7158981addf899b119cd448 (patch) | |
tree | 5de0c4ac29404d4c35e8303646b1626b0578282f /Lib/zipfile.py | |
parent | 87b3e202d46cdeb0a6b1ef041579a5ebc7c826a9 (diff) | |
download | cpython-4352ca234e979ad1c7158981addf899b119cd448.zip cpython-4352ca234e979ad1c7158981addf899b119cd448.tar.gz cpython-4352ca234e979ad1c7158981addf899b119cd448.tar.bz2 |
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 e730ae7effe4f13b24f1b5fb1fca005709c86acb)
Co-authored-by: Kevin Mehall <km@kevinmehall.net>
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 67cfdfb..34d2fa4 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -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: |