Calculate data_start after parse_extra_field
Some extra fields may alter offsets, e.g. Zip64.
This commit is contained in:
parent
d2ccfc16f7
commit
86d9d20884
1 changed files with 18 additions and 18 deletions
36
src/read.rs
36
src/read.rs
|
@ -344,23 +344,6 @@ fn central_header_to_zip_file<R: Read+io::Seek>(reader: &mut R, archive_offset:
|
|||
false => file_comment_raw.from_cp437(),
|
||||
};
|
||||
|
||||
// Remember end of central header
|
||||
let return_position = try!(reader.seek(io::SeekFrom::Current(0)));
|
||||
|
||||
// Parse local header
|
||||
try!(reader.seek(io::SeekFrom::Start(offset)));
|
||||
let signature = try!(reader.read_u32::<LittleEndian>());
|
||||
if signature != spec::LOCAL_FILE_HEADER_SIGNATURE
|
||||
{
|
||||
return Err(ZipError::InvalidArchive("Invalid local file header"))
|
||||
}
|
||||
|
||||
try!(reader.seek(io::SeekFrom::Current(22)));
|
||||
let file_name_length = try!(reader.read_u16::<LittleEndian>()) as u64;
|
||||
let extra_field_length = try!(reader.read_u16::<LittleEndian>()) as u64;
|
||||
let magic_and_header = 4 + 22 + 2 + 2;
|
||||
let data_start = offset + magic_and_header + file_name_length + extra_field_length;
|
||||
|
||||
// Construct the result
|
||||
let mut result = ZipFileData
|
||||
{
|
||||
|
@ -376,7 +359,7 @@ fn central_header_to_zip_file<R: Read+io::Seek>(reader: &mut R, archive_offset:
|
|||
file_name_raw: file_name_raw,
|
||||
file_comment: file_comment,
|
||||
header_start: offset,
|
||||
data_start: data_start,
|
||||
data_start: 0,
|
||||
external_attributes: external_file_attributes,
|
||||
};
|
||||
|
||||
|
@ -385,6 +368,23 @@ fn central_header_to_zip_file<R: Read+io::Seek>(reader: &mut R, archive_offset:
|
|||
Err(e) => try!(Err(e)),
|
||||
}
|
||||
|
||||
// Remember end of central header
|
||||
let return_position = try!(reader.seek(io::SeekFrom::Current(0)));
|
||||
|
||||
// Parse local header
|
||||
try!(reader.seek(io::SeekFrom::Start(result.header_start)));
|
||||
let signature = try!(reader.read_u32::<LittleEndian>());
|
||||
if signature != spec::LOCAL_FILE_HEADER_SIGNATURE
|
||||
{
|
||||
return Err(ZipError::InvalidArchive("Invalid local file header"))
|
||||
}
|
||||
|
||||
try!(reader.seek(io::SeekFrom::Current(22)));
|
||||
let file_name_length = try!(reader.read_u16::<LittleEndian>()) as u64;
|
||||
let extra_field_length = try!(reader.read_u16::<LittleEndian>()) as u64;
|
||||
let magic_and_header = 4 + 22 + 2 + 2;
|
||||
result.data_start = result.header_start + magic_and_header + file_name_length + extra_field_length;
|
||||
|
||||
// Go back after the central header
|
||||
try!(reader.seek(io::SeekFrom::Start(return_position)));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue