Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0methean committed Apr 14, 2024
1 parent c4f91c2 commit d23f036
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,15 @@ impl<W: Write + Seek> ZipWriter<W> {
self.switch_to_non_encrypting_writer()?;
// Make sure this is the last file, and that no shallow copies of it remain; otherwise we'd
// overwrite a valid file and corrupt the archive
let last_file_start = last_file.data_start.get().unwrap();
if self
.files
.iter()
.flat_map(|file| file.data_start.get())
.all(|start| start < last_file_start)
{
let rewind_safe: bool = match last_file.data_start.get() {
None => self.files.is_empty(),
Some(last_file_start) => self.files.iter().all(|file| {
file.data_start
.get()
.is_some_and(|start| start < last_file_start)
}),
};
if rewind_safe {
self.inner
.get_plain()
.seek(SeekFrom::Start(last_file.header_start))?;
Expand Down

0 comments on commit d23f036

Please sign in to comment.