Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zip64: fix zip64 extended information issue #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1873,12 +1873,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 @@ -1914,7 +1923,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 @@ -1927,6 +1936,10 @@ 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)?;

let extra_field = Arc::get_mut(file.extra_field.as_mut().unwrap()).unwrap();
extra_field[..block.len()].copy_from_slice(&block);

Ok(())
}

Expand Down