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

Prevent subtract with overflow #41

Merged
merged 1 commit into from
Jul 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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