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.
This commit is contained in:
Mathijs van de Nes 2018-10-16 17:42:48 +02:00
parent 74639e46d7
commit dbb871245b

View file

@ -405,17 +405,30 @@ fn parse_extra_field(file: &mut ZipFileData, data: &[u8]) -> ZipResult<()>
{ {
let kind = reader.read_u16::<LittleEndian>()?; let kind = reader.read_u16::<LittleEndian>()?;
let len = reader.read_u16::<LittleEndian>()?; let len = reader.read_u16::<LittleEndian>()?;
let mut len_left = len as i64;
match kind match kind
{ {
// Zip64 extended information extra field // Zip64 extended information extra field
0x0001 => { 0x0001 => {
if file.uncompressed_size == 0xFFFFFFFF {
file.uncompressed_size = reader.read_u64::<LittleEndian>()?; file.uncompressed_size = reader.read_u64::<LittleEndian>()?;
len_left -= 8;
}
if file.compressed_size == 0xFFFFFFFF {
file.compressed_size = reader.read_u64::<LittleEndian>()?; file.compressed_size = reader.read_u64::<LittleEndian>()?;
reader.read_u64::<LittleEndian>()?; // relative header offset len_left -= 8;
reader.read_u32::<LittleEndian>()?; // disk start number }
// 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(()) Ok(())
} }