From 17f028d84280ed41d71374f8c9be7e3f4304bb99 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Fri, 26 Jan 2024 16:24:21 +0100 Subject: [PATCH] fix: Read 64-bit extra fields compressed/uncompressed sizes properly --- crates/rc-zip/src/format/directory_header.rs | 5 +++-- crates/rc-zip/src/format/eocd.rs | 1 + crates/rc-zip/src/format/extra_field.rs | 1 + crates/rc-zip/src/reader/archive_reader.rs | 13 ++++++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/rc-zip/src/format/directory_header.rs b/crates/rc-zip/src/format/directory_header.rs index cabdf5c..85d2da0 100644 --- a/crates/rc-zip/src/format/directory_header.rs +++ b/crates/rc-zip/src/format/directory_header.rs @@ -138,10 +138,11 @@ impl DirectoryHeader { let mut extra_fields: Vec = Vec::new(); let settings = ExtraFieldSettings { - needs_compressed_size: self.uncompressed_size == !0u32, - needs_uncompressed_size: self.compressed_size == !0u32, + needs_compressed_size: self.compressed_size == !0u32, + needs_uncompressed_size: self.uncompressed_size == !0u32, needs_header_offset: self.header_offset == !0u32, }; + trace!("extra field settings: {:#?}", settings); let mut slice = &self.extra.0[..]; while !slice.is_empty() { diff --git a/crates/rc-zip/src/format/eocd.rs b/crates/rc-zip/src/format/eocd.rs index 48c187e..cef06bf 100644 --- a/crates/rc-zip/src/format/eocd.rs +++ b/crates/rc-zip/src/format/eocd.rs @@ -82,6 +82,7 @@ impl EndOfCentralDirectoryRecord { } /// 4.3.15 Zip64 end of central directory locator +#[derive(Debug)] pub struct EndOfCentralDirectory64Locator { /// number of the disk with the start of the zip64 end of central directory pub dir_disk_number: u32, diff --git a/crates/rc-zip/src/format/extra_field.rs b/crates/rc-zip/src/format/extra_field.rs index 6a4071f..f86d953 100644 --- a/crates/rc-zip/src/format/extra_field.rs +++ b/crates/rc-zip/src/format/extra_field.rs @@ -29,6 +29,7 @@ impl<'a> ExtraFieldRecord<'a> { // is created. The order of the fields in the zip64 extended information record // is fixed, but the fields MUST only appear if the corresponding Local or // Central directory record field is set to 0xFFFF or 0xFFFFFFFF. +#[derive(Debug)] pub(crate) struct ExtraFieldSettings { pub(crate) needs_uncompressed_size: bool, pub(crate) needs_compressed_size: bool, diff --git a/crates/rc-zip/src/reader/archive_reader.rs b/crates/rc-zip/src/reader/archive_reader.rs index b5c49de..f42a6b9 100644 --- a/crates/rc-zip/src/reader/archive_reader.rs +++ b/crates/rc-zip/src/reader/archive_reader.rs @@ -173,7 +173,11 @@ impl ArchiveReader { } { None => Err(FormatError::DirectoryEndSignatureNotFound.into()), Some(mut eocdr) => { - trace!(?eocdr, "ReadEocd | found end of central directory record"); + trace!( + ?eocdr, + size = self.size, + "ReadEocd | found end of central directory record" + ); buffer.reset(); eocdr.offset += self.size - haystack_size; @@ -194,6 +198,7 @@ impl ArchiveReader { }); Ok(R::Continue) } else { + trace!("ReadEocd | transition to ReadEocd64Locator"); transition!(self.state => (S::ReadEocd { mut buffer, .. }) { buffer.reset(); S::ReadEocd64Locator { buffer, eocdr } @@ -211,6 +216,8 @@ impl ArchiveReader { } Err(nom::Err::Error(_)) | Err(nom::Err::Failure(_)) => { // we don't have a zip64 end of central directory locator - that's ok! + trace!("ReadEocd64Locator | no zip64 end of central directory locator"); + trace!("ReadEocd64Locator | data we got: {:02x?}", buffer.data()); transition!(self.state => (S::ReadEocd64Locator { mut buffer, eocdr }) { buffer.reset(); S::ReadCentralDirectory { @@ -222,6 +229,10 @@ impl ArchiveReader { Ok(R::Continue) } Ok((_, locator)) => { + trace!( + ?locator, + "ReadEocd64Locator | found zip64 end of central directory locator" + ); transition!(self.state => (S::ReadEocd64Locator { mut buffer, eocdr }) { buffer.reset(); S::ReadEocd64 {