From f10ee6aa2add873970b3ad3d88f2b3e3ec01fcbe Mon Sep 17 00:00:00 2001 From: xenofem Date: Wed, 27 Apr 2022 12:47:43 -0400 Subject: [PATCH] zip: go back to saying we're unix, we just forgot to include unix permissions in the external file attributes --- src/zip.rs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/zip.rs b/src/zip.rs index a686a75..714ed53 100644 --- a/src/zip.rs +++ b/src/zip.rs @@ -136,24 +136,13 @@ impl UploadedFile { fn central_directory_header(&self, local_header_offset: usize, hash: u32) -> Vec { let mut header = vec![ - // Central directory file header signature - 0x50, 0x4b, 0x01, 0x02, - // Made by a "DOS" system supporting version 4.5 - if we - // say it's made by a Unix system, then unzip will expect - // it to have embedded Unix permission information, and - // will set all the files to mode 000 when that's not - // present :/ - 45, 0, + 0x50, 0x4b, 0x01, 0x02, // Central directory file header signature + 45, 3, // Made by a Unix system supporting version 4.5 ]; header.append(&mut self.shared_header_fields(Some(hash))); - header.append(&mut vec![ - 0, 0, // File comment length: 0 - 0, 0, // Disk number where file starts: 0 - 0, 0, // Internal file attributes: nothing - 0, 0, 0, 0, // External file attributes: nothing - 0xff, 0xff, 0xff, - 0xff, // Relative offset of local file header: placeholder, see ZIP64 data - ]); + append_0(&mut header, 8); // Comment length, disk number, internal attributes, DOS external attributes + append_value(&mut header, 0o100644, 2); // Unix external file attributes: -rw-r--r-- + append_ff(&mut header, 4); // Relative offset of local file header: placeholder, see ZIP64 data header.append(&mut self.name.clone().into_bytes()); header.append(&mut self.extra_field(local_header_offset)); header @@ -179,7 +168,7 @@ fn end_of_central_directory(files: &[UploadedFile]) -> Vec { ]; append_0(&mut eocd, 7); // pad out the rest of the size field eocd.append(&mut vec![ - 45, 0, // Made by a "DOS" system supporting version 4.5, see above + 45, 3, // Made by a Unix system supporting version 4.5 45, 0, // Minimum version 4.5 to extract ]); append_0(&mut eocd, 8); // Two 4-byte disk numbers, both 0