Fix bad merge: revert extra_field_length change

This commit is contained in:
Chris Hennick 2024-05-09 17:58:45 -07:00 committed by GitHub
parent 0482a1329a
commit 00537ae34e
Signed by: DevComp
GPG key ID: B5690EEEBB952194

View file

@ -844,14 +844,16 @@ impl<W: Write + Seek> ZipWriter<W> {
// file name length // file name length
writer.write_u16_le(file.file_name_raw.len() as u16)?; writer.write_u16_le(file.file_name_raw.len() as u16)?;
// extra field length // extra field length
let mut extra_field_length = if file.large_file { 20 } else { 0 }; let mut extra_field_length = file.extra_field_len();
if let Some(field) = &file.extra_field { if file.large_file {
extra_field_length += field.len(); extra_field_length += 20;
} }
match extra_field_length.try_into() { if extra_field_length + file.central_extra_field_len() > u16::MAX as usize {
Ok(length_u16) => writer.write_u16_le(length_u16)?, let _ = self.abort_file();
Err(_) => return Err(ZipError::InvalidArchive("Extra field is too long")), return Err(InvalidArchive("Extra data field is too large"));
} }
let extra_field_length = extra_field_length as u16;
writer.write_u16_le(extra_field_length)?;
// file name // file name
writer.write_all(&file.file_name_raw)?; writer.write_all(&file.file_name_raw)?;
// zip64 extra field // zip64 extra field