Skip to content

Commit

Permalink
fix: Read 64-bit extra fields compressed/uncompressed sizes properly
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jan 26, 2024
1 parent e0ca548 commit 17f028d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions crates/rc-zip/src/format/directory_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ impl DirectoryHeader {
let mut extra_fields: Vec<ExtraField> = 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() {
Expand Down
1 change: 1 addition & 0 deletions crates/rc-zip/src/format/eocd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/rc-zip/src/format/extra_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion crates/rc-zip/src/reader/archive_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 }
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 17f028d

Please sign in to comment.