Skip to content

Commit

Permalink
WIP: fix #195
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0methean committed Jul 28, 2024
1 parent fd5f804 commit 412dad8
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,11 @@ impl<W: Write + Seek> ZipWriter<W> {
}
file.central_extra_field = Some(data.clone());
}
debug_assert!(file.data_start.get().is_none());
file.data_start.get_or_init(|| self.stats.start);
self.writing_to_file = true;
self.stats.bytes_written = 0;
self.stats.hasher = Hasher::new();
match options.encrypt_with {
#[cfg(feature = "aes-crypto")]
Some(EncryptWith::Aes { mode, password }) => {
Expand All @@ -1016,19 +1021,12 @@ impl<W: Write + Seek> ZipWriter<W> {
keys,
};
let crypto_header = [0u8; 12];

zipwriter.write_all(&crypto_header)?;
self.stats.start = zipwriter.writer.stream_position()?;
self.stats.hasher.update(&crypto_header);
self.inner = Storer(MaybeEncrypted::ZipCrypto(zipwriter));
}
None => {}
}

debug_assert!(file.data_start.get().is_none());
file.data_start.get_or_init(|| self.stats.start);
self.writing_to_file = true;
self.stats.bytes_written = 0;
self.stats.hasher = Hasher::new();
}
Ok(())
}
Expand Down Expand Up @@ -3498,4 +3496,18 @@ mod test {
assert!(archive.comment().starts_with(&[33]));
Ok(())
}

#[cfg(unix)]
#[test]
fn test_crc_bug195() -> ZipResult<()> {
let file = File::create("test.zip").unwrap();

Check failure on line 3503 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: ubuntu-latest, nightly

failed to resolve: use of undeclared type `File`

Check failure on line 3503 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: ubuntu-latest, msrv

failed to resolve: use of undeclared type `File`

Check failure on line 3503 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: ubuntu-latest, stable

failed to resolve: use of undeclared type `File`

Check failure on line 3503 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

failed to resolve: use of undeclared type `File`

Check failure on line 3503 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs

failed to resolve: use of undeclared type `File`
let mut zip = ZipWriter::new(file);
let options = SimpleFileOptions::default()
.compression_method(zip::CompressionMethod::Stored)

Check failure on line 3506 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: ubuntu-latest, nightly

failed to resolve: use of undeclared crate or module `zip`

Check failure on line 3506 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: ubuntu-latest, msrv

failed to resolve: use of undeclared crate or module `zip`

Check failure on line 3506 in src/write.rs

View workflow job for this annotation

GitHub Actions / Build and test --no-default-features: ubuntu-latest, stable

failed to resolve: use of undeclared crate or module `zip`

Check failure on line 3506 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs (--no-default-features)

failed to resolve: use of undeclared crate or module `zip`

Check failure on line 3506 in src/write.rs

View workflow job for this annotation

GitHub Actions / style_and_docs

failed to resolve: use of undeclared crate or module `zip`
.large_file(true);
zip.start_file("hello_world.txt", options).unwrap();
zip.write(b"Hello\nWorld!").unwrap();
zip.finish().unwrap();
Ok(())
}
}

0 comments on commit 412dad8

Please sign in to comment.