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 15, 2024
1 parent 6d39456 commit a24edbc
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1828,12 +1828,21 @@ 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)?;

file.compressed_size = spec::ZIP64_BYTES_THR;
file.uncompressed_size = spec::ZIP64_BYTES_THR;
} else {
// check compressed size as well as it can also be slightly larger than uncompressed size
if file.compressed_size > spec::ZIP64_BYTES_THR {
Expand Down Expand Up @@ -1869,7 +1878,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 +1891,9 @@ 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.extra_field = Some(block.into_vec().into());

Ok(())
}

Expand Down

0 comments on commit a24edbc

Please sign in to comment.