Skip to content

gh-154842: Reject repack() while a reading handle is open - #154843

Open
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:zipfile-repack-open-readers
Open

gh-154842: Reject repack() while a reading handle is open#154843
fedonman wants to merge 1 commit into
python:mainfrom
fedonman:zipfile-repack-open-readers

Conversation

@fedonman

@fedonman fedonman commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

ZipFile.repack() moves member data to lower offsets, but a ZipExtFile from an earlier
open() keeps its own absolute position, so it silently returned data from the wrong place
and a full read failed with BadZipFile: Bad CRC-32. Raise ValueError while an open
reading handle exists, as the writing-handle case already does.

The test fails without the guard. repack() is new in 3.16, so no NEWS entry.

ZipFile.repack() moves member data, but a ZipExtFile from an earlier open()
keeps its own absolute position, so it silently returned data from the wrong
place and a full read failed with a misleading CRC error. Raise ValueError
while _fileRefCnt shows an open reading handle, as the writing-handle case
already does.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33806065 | 📁 Comparing 82d68c7 against main (8b048eb)

  🔍 Preview build  

1 file changed
± library/zipfile.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant