Skip to content

Commit

Permalink
zip64: fix zip64 extended information issue
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyxuyang committed Oct 14, 2024
1 parent 6d39456 commit 0c8bf87
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1828,11 +1828,17 @@ fn update_aes_extra_data<W: Write + Seek>(writer: &mut W, file: &mut ZipFileData
Ok(())
}

fn update_local_file_header<T: Write + Seek>(writer: &mut T, file: &ZipFileData) -> ZipResult<()> {
fn update_local_file_header<T: Write + Seek>(
writer: &mut T,
file: &mut ZipFileData,
) -> ZipResult<()> {
const CRC32_OFFSET: u64 = 14;
writer.seek(SeekFrom::Start(file.header_start + CRC32_OFFSET))?;
writer.write_u32_le(file.crc32)?;
if file.large_file {
writer.write_u32_le(spec::ZIP64_BYTES_THR as u32)?;
writer.write_u32_le(spec::ZIP64_BYTES_THR as u32)?;

update_local_zip64_extra_field(writer, file)?;
} else {
// check compressed size as well as it can also be slightly larger than uncompressed size
Expand Down Expand Up @@ -1869,7 +1875,7 @@ fn write_central_directory_header<T: Write>(writer: &mut T, file: &ZipFileData)

fn update_local_zip64_extra_field<T: Write + Seek>(
writer: &mut T,
file: &ZipFileData,
file: &mut ZipFileData,
) -> ZipResult<()> {
let block = file.zip64_extra_field_block().ok_or(InvalidArchive(
"Attempted to update a nonexistent ZIP64 extra field",
Expand All @@ -1882,6 +1888,11 @@ fn update_local_zip64_extra_field<T: Write + Seek>(
writer.seek(SeekFrom::Start(zip64_extra_field_start))?;
let block = block.serialize();
writer.write_all(&block)?;

file.compressed_size = spec::ZIP64_BYTES_THR;
file.uncompressed_size = spec::ZIP64_BYTES_THR;
file.extra_field = Some(block.clone().into_vec().into());

Ok(())
}

Expand Down

0 comments on commit 0c8bf87

Please sign in to comment.