feat: Add method decompressed_size()
so non-recursive ZIP bombs can be detected
This commit is contained in:
parent
e273ff40d5
commit
aa890fa634
1 changed files with 13 additions and 0 deletions
13
src/read.rs
13
src/read.rs
|
@ -356,6 +356,19 @@ impl<R> ZipArchive<R> {
|
||||||
comment: comment.into_boxed_slice().into(),
|
comment: comment.into_boxed_slice().into(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Total size of the files in the archive, if it can be known. Doesn't include directories or
|
||||||
|
/// metadata.
|
||||||
|
pub fn decompressed_size(&self) -> Option<u128> {
|
||||||
|
let mut total = 0u128;
|
||||||
|
for file in self.shared.files.values() {
|
||||||
|
if file.using_data_descriptor {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
total = total.checked_add(file.uncompressed_size as u128)?;
|
||||||
|
}
|
||||||
|
Some(total)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Read + Seek> ZipArchive<R> {
|
impl<R: Read + Seek> ZipArchive<R> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue