zip: set bit flag for UTF-8 filenames, bump minimum zip version to 6.3

This commit is contained in:
xenofem 2022-04-27 20:31:12 -04:00
parent 2ec295e606
commit b832ae5a95

View file

@ -87,9 +87,10 @@ impl UploadedFile {
/// through "Extra field length". /// through "Extra field length".
fn shared_header_fields(&self, hash: Option<u32>) -> Vec<u8> { fn shared_header_fields(&self, hash: Option<u32>) -> Vec<u8> {
let mut fields = vec![ let mut fields = vec![
45, 0, // Minimum version required to extract: 4.5 for ZIP64 extensions 63, 0, // Minimum version required to extract: 6.3 for UTF-8 filenames
0b00001000, 0, // General purpose bit flag: size and CRC-32 in data descriptor 0b00001000, // General purpose bit flag: bit 3 - size and CRC-32 in data descriptor
0, 0, // Compression method: none 0b00001000, // General purpose bit flag: bit 11 - UTF-8 filenames
0, 0, // Compression method: none
]; ];
append_value(&mut fields, fat_timestamp(self.modtime) as u64, 4); append_value(&mut fields, fat_timestamp(self.modtime) as u64, 4);
// Use 0s as a placeholder if the CRC-32 hash isn't known yet // Use 0s as a placeholder if the CRC-32 hash isn't known yet
@ -137,7 +138,7 @@ impl UploadedFile {
fn central_directory_header(&self, local_header_offset: u64, hash: u32) -> Vec<u8> { fn central_directory_header(&self, local_header_offset: u64, hash: u32) -> Vec<u8> {
let mut header = vec![ let mut header = vec![
0x50, 0x4b, 0x01, 0x02, // Central directory file header signature 0x50, 0x4b, 0x01, 0x02, // Central directory file header signature
45, 3, // Made by a Unix system supporting version 4.5 63, 3, // Made by a Unix system supporting version 6.3
]; ];
header.append(&mut self.shared_header_fields(Some(hash))); header.append(&mut self.shared_header_fields(Some(hash)));
append_0(&mut header, 8); // Comment length, disk number, internal attributes, DOS external attributes append_0(&mut header, 8); // Comment length, disk number, internal attributes, DOS external attributes
@ -168,8 +169,8 @@ fn end_of_central_directory(files: &[UploadedFile]) -> Vec<u8> {
]; ];
append_0(&mut eocd, 7); // pad out the rest of the size field append_0(&mut eocd, 7); // pad out the rest of the size field
eocd.append(&mut vec![ eocd.append(&mut vec![
45, 3, // Made by a Unix system supporting version 4.5 63, 3, // Made by a Unix system supporting version 6.3
45, 0, // Minimum version 4.5 to extract 63, 0, // Minimum version 6.3 to extract
]); ]);
append_0(&mut eocd, 8); // Two 4-byte disk numbers, both 0 append_0(&mut eocd, 8); // Two 4-byte disk numbers, both 0
// Number of central directory records, on this disk and in total // Number of central directory records, on this disk and in total