Repository navigation
Conversation
_ZipRepacker.repack() updates ZipInfo.header_offset for each member before moving that member's bytes, so a failing _copy_bytes() left the in-memory offsets describing a layout that was never written. remove() has already set _didModify, so a later close() committed a central directory built from those offsets, and the archive became unreadable even though the caller had handled the error. ZipFile.repack() now snapshots the offsets of the surviving and the removed entries and restores them if the repack raises. The copy only ever moves data to lower offsets, so a partial move never overwrites its own source and the archive falls back to the state of a remove() with no repack().
Restoring every offset after a failed repack() is wrong once an entry has been moved over its old position: the restored offset then points at overwritten data. Instead, set each entry's header_offset only after its bytes have been copied, so entries that finished moving or were never touched stay readable. This also drops the list(removed) copy, which was only needed because the rollback read removed a second time.
repack() failsrepack()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_ZipRepacker.repack()set each entry'sheader_offsetbefore moving its bytes, so after a failed move a laterclose()wrote a central directory pointing at data that was never moved. Each offset is now set only after that entry has been moved, so entries that finished moving or were never touched stay readable.ZipFile.close()writes wrong offsets after a failedrepack()#156434