Fix overflow in directory counts of ZIP64 files

This commit is contained in:
nickbabcock 2020-08-10 21:22:49 -05:00
parent fbffaed42a
commit ef5ce23d85
2 changed files with 18 additions and 1 deletions

View file

@ -263,7 +263,13 @@ impl<R: Read + io::Seek> ZipArchive<R> {
);
}
let directory_start = footer.central_directory_offset + archive_offset;
let directory_start = footer
.central_directory_offset
.checked_add(archive_offset)
.ok_or_else(|| {
ZipError::InvalidArchive("Invalid central directory size or offset")
})?;
Ok((
archive_offset,
directory_start,
@ -834,6 +840,17 @@ mod test {
assert!(reader.is_err());
}
#[test]
fn invalid_offset2() {
use super::ZipArchive;
use std::io;
let mut v = Vec::new();
v.extend_from_slice(include_bytes!("../tests/data/invalid_offset2.zip"));
let reader = ZipArchive::new(io::Cursor::new(v));
assert!(reader.is_err());
}
#[test]
fn zip64_with_leading_junk() {
use super::ZipArchive;

Binary file not shown.