Commit 9ec41b7
Fix thread safety of zipfile._SharedFile.tell
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.
Prior to this fix, the test case in
https://bugs.python.org/issue42369#msg381212
reliably caused a `zipfile.BadZipFile: Bad CRC-32 for file 'file1'`
after a few dozen reads; with this fix I have not seen this error.
From-PR: gh#python/cpython!26974
Fixes: gh#python#86535
Patch: bh42369-thread-safety-zipfile-SharedFile.patch1 parent d7133c7 commit 9ec41b7
File tree
2 files changed
+15
-0
lines changed- Lib
- Misc/NEWS.d/next/Library
2 files changed
+15
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
718 | 718 | | |
719 | 719 | | |
720 | 720 | | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
721 | 735 | | |
722 | 736 | | |
723 | 737 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments