Skip to content

Commit

Permalink
fix: Process ZIP files with up to a 65,978-byte comment (zip-rs#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pr0methean committed May 6, 2024
1 parent a8ec016 commit 5237543
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ impl CentralDirectoryEnd {

pub fn find_and_parse<T: Read + Seek>(reader: &mut T) -> ZipResult<(CentralDirectoryEnd, u64)> {
const HEADER_SIZE: u64 = 22;
const MAX_HEADER_AND_COMMENT_SIZE: u64 = 66000;
const BYTES_BETWEEN_MAGIC_AND_COMMENT_SIZE: u64 = HEADER_SIZE - 6;
let file_length = reader.seek(io::SeekFrom::End(0))?;

let search_upper_bound = file_length.saturating_sub(HEADER_SIZE + u16::MAX as u64);
let search_upper_bound = file_length.saturating_sub(MAX_HEADER_AND_COMMENT_SIZE);

if file_length < HEADER_SIZE {
return Err(ZipError::InvalidArchive("Invalid zip header"));
Expand Down

0 comments on commit 5237543

Please sign in to comment.