From 20e4c182801b23a5c698f3e5db20c816b8781308 Mon Sep 17 00:00:00 2001 From: Chris Hennick <4961925+Pr0methean@users.noreply.github.com> Date: Thu, 9 May 2024 13:36:37 -0700 Subject: [PATCH] Fix type mismatch for extra_field_length --- src/write.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/write.rs b/src/write.rs index 56a7ff66..e6737f0c 100644 --- a/src/write.rs +++ b/src/write.rs @@ -1759,7 +1759,11 @@ fn write_local_file_header(writer: &mut T, file: &ZipFileData) -> ZipR if let Some(field) = file.extra_field { extra_field_length += field.len(); } - writer.write_u16_le(extra_field_length)?; + match extra_field_length.try_into::() { + Ok(length_u16) => writer.write_u16_le(length_u16)?, + Err(_) => return ZipError::InvalidArchive("Extra field is too long"), + } + writer.write_u16_le(extra_field_length.try_into().map_err(|_| ZipError))?; // file name writer.write_all(&file.file_name_raw)?; // zip64 extra field