Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Prevent subtract with overflow
Browse files Browse the repository at this point in the history
This changes assumes this only happens when the archive is invalid.

Fixes #40
  • Loading branch information
killercup committed Jun 27, 2017
1 parent 5c12e51 commit 57a6514
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ impl<R: Read+io::Seek> ZipArchive<R>

// Some zip files have data prepended to them, resulting in the offsets all being too small. Get the amount of
// error by comparing the actual file position we found the CDE at with the offset recorded in the CDE.
let archive_offset = cde_start_pos - footer.central_directory_size - footer.central_directory_offset;
let archive_offset = cde_start_pos.checked_sub(footer.central_directory_size)
.and_then(|x| x.checked_sub(footer.central_directory_offset))
.ok_or(ZipError::InvalidArchive("Invalid central directory size or offset"))?;

let directory_start = (footer.central_directory_offset + archive_offset) as u64;
let number_of_files = footer.number_of_files_on_this_disk as usize;
Expand Down

0 comments on commit 57a6514

Please sign in to comment.