Repository navigation
fix(write): raw_copy_file corrupted ZipCrypto metadata - #1288
Merged
Merged
Conversation
Pr0methean
approved these changes
Nov 10, 2026
Merged
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.
Hi again!
(AI use disclosure: Claude-generated PR description edited by me. The code changes are also Claude-created, I've reviewed them and it looks good.)
Here is another one from Cmdr's in-place zip editing:
deleting _one_ filefrom a password-protected zip left every otherZipCryptoentry in it undecryptable.The problem:
raw_copy_filewrites a ZipCrypto entry with a clear encrypted flag (bit 0), so readers serve the ciphertext as plaintext.raw_copy_optionsbuilds onZipFile::options(), which carries AES settings but no ZipCrypto state (it can't, there's no password), sostart_entrynever sets the flag. It drops the data descriptor flag (bit 3) too, and for ZipCrypto that one matters on its own: under bit 3, the password check byte is the DOS time's high byte (that's how Info-ZIP'szip -eand this crate's writer do it), otherwise it's the CRC's. So even with bit 0 back, the right password looks wrong.(AES entries are fine since #1078:
options()carries their mode, and the check lives in the copied bytes.)A second bug with the same fix: a raw copy into
ZipWriter::new_streamsets bit 3 (because!seek_possible) and zeroes the sizes in the local header, butfinish_filewrites no data descriptor for a raw entry. So a streaming reader can't find where the entry ends:cat out.zip | bsdtar -xOf -fails with "ZIP bad CRC".add_prepared_filealready works around this by writing the descriptor itself.What the PR changes:
ZipRawValues::encrypted_with_descriptorcarries them intostart_entry, which applies them after its own data descriptor default.raw_copy_file_rename_internalwrites a data descriptor after the copied bytes when bit 3 is set, same asadd_prepared_file.raw_copy_file_touch's docs mention the one case no copy can fix: a new time with a different high byte breaks a bit-3 ZipCrypto entry's password check, since the check byte sits encrypted in the copied bytes.This PR makes no public API change.
Tests:
raw_copy_file_keeps_a_zipcrypto_entry_decryptable(end ofwrite.rs'stestsmodule):raw_copy_fileandraw_copy_file_renameof a ZipCrypto entry keep bits 0 and 3, and the copy decrypts with the password.raw_copy_to_a_stream_writes_a_data_descriptor(tests/data_descriptor.rs).Both fail on
masterwithout the fix.cargo test(default, all, no-default,deflate-zopfli, anddeflate-flate2-zlib-rsfeatures), clippy, doc, and fmt pass, apart from clippy'sfield_reassign_with_defaultinextra_field.rswith--no-default-features, which fails onmastertoo.Thanks again!
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.