From dbb871245bea1830062ecebd22562eaac8d5e350 Mon Sep 17 00:00:00 2001 From: Mathijs van de Nes Date: Tue, 16 Oct 2018 17:42:48 +0200 Subject: [PATCH] Fix parse_extra_field for zip64 The specification states that fields are only present when their corresponding entry in the central directory is set to 0xFFFFFFFF. --- src/read.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/read.rs b/src/read.rs index 3949cf4e..0691a397 100644 --- a/src/read.rs +++ b/src/read.rs @@ -405,17 +405,30 @@ fn parse_extra_field(file: &mut ZipFileData, data: &[u8]) -> ZipResult<()> { let kind = reader.read_u16::()?; let len = reader.read_u16::()?; + let mut len_left = len as i64; match kind { // Zip64 extended information extra field 0x0001 => { - file.uncompressed_size = reader.read_u64::()?; - file.compressed_size = reader.read_u64::()?; - reader.read_u64::()?; // relative header offset - reader.read_u32::()?; // disk start number + if file.uncompressed_size == 0xFFFFFFFF { + file.uncompressed_size = reader.read_u64::()?; + len_left -= 8; + } + if file.compressed_size == 0xFFFFFFFF { + file.compressed_size = reader.read_u64::()?; + len_left -= 8; + } + // Unparsed fields: + // u64: relative header offset + // u32: disk start number }, - _ => { reader.seek(io::SeekFrom::Current(len as i64))?; }, - }; + _ => {}, + } + + // We could also check for < 0 to check for errors + if len_left > 0 { + reader.seek(io::SeekFrom::Current(len_left))?; + } } Ok(()) }