aboutsummaryrefslogtreecommitdiff
path: root/src/zip/driver.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/zip/driver.rs')
-rw-r--r--src/zip/driver.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/zip/driver.rs b/src/zip/driver.rs
index 99b409d..4782e65 100644
--- a/src/zip/driver.rs
+++ b/src/zip/driver.rs
@@ -1,5 +1,6 @@
1use crate::driver::{ArchiveRead, ArchiveWrite, Driver}; 1use crate::driver::{ArchiveRead, ArchiveWrite, Driver};
2use crate::utils::ReadUtils; 2use crate::utils::ReadUtils;
3use crate::zip::cp437::FromCp437;
3use crate::zip::structs::{deserialize, Cdr, Eocdr, Eocdr64, Eocdr64Locator, ExtraHeader}; 4use crate::zip::structs::{deserialize, Cdr, Eocdr, Eocdr64, Eocdr64Locator, ExtraHeader};
4use crate::zip::{ 5use crate::zip::{
5 BitFlag, CompressionMethod, ZipError, ZipFileInfo, ZipFileReader, ZipFileWriter, ZipResult, 6 BitFlag, CompressionMethod, ZipError, ZipFileInfo, ZipFileReader, ZipFileWriter, ZipResult,
@@ -77,7 +78,7 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> {
77 let comment = { 78 let comment = {
78 let mut buf: Vec<u8> = vec![0; eocdr.comment_len as usize]; 79 let mut buf: Vec<u8> = vec![0; eocdr.comment_len as usize];
79 io.read(&mut buf)?; 80 io.read(&mut buf)?;
80 String::from_utf8(buf).map_err(|_| ZipError::InvalidArchiveComment)? 81 String::from_cp437(buf)
81 }; 82 };
82 83
83 // Try to find eocdr64locator 84 // Try to find eocdr64locator
@@ -116,14 +117,23 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> {
116 } 117 }
117 p += 4; 118 p += 4;
118 let cdr: Cdr = deserialize(&buf[p..p + 42]).unwrap(); 119 let cdr: Cdr = deserialize(&buf[p..p + 42]).unwrap();
120 let bit_flag = BitFlag::new(cdr.bit_flag);
119 p += 42; 121 p += 42;
120 let name = String::from_utf8(buf[p..p + cdr.name_len as usize].into()) 122 let name = if bit_flag.is_utf8() {
121 .map_err(|_| ZipError::InvalidFileName)?; 123 String::from_utf8(buf[p..p + cdr.name_len as usize].to_vec())
124 .map_err(|_| ZipError::InvalidFileName)?
125 } else {
126 String::from_cp437(&buf[p..p + cdr.name_len as usize])
127 };
122 p += cdr.name_len as usize; 128 p += cdr.name_len as usize;
123 let extra_fields: Vec<u8> = buf[p..p + cdr.extra_field_len as usize].into(); 129 let extra_fields: Vec<u8> = buf[p..p + cdr.extra_field_len as usize].into();
124 p += cdr.extra_field_len as usize; 130 p += cdr.extra_field_len as usize;
125 let comment = String::from_utf8(buf[p..p + cdr.comment_len as usize].into()) 131 let comment = if bit_flag.is_utf8() {
126 .map_err(|_| ZipError::InvalidFileComment)?; 132 String::from_utf8(buf[p..p + cdr.comment_len as usize].to_vec())
133 .map_err(|_| ZipError::InvalidFileComment)?
134 } else {
135 String::from_cp437(&buf[p..p + cdr.comment_len as usize])
136 };
127 p += cdr.comment_len as usize; 137 p += cdr.comment_len as usize;
128 138
129 let mut compressed_size = cdr.compressed_size as u64; 139 let mut compressed_size = cdr.compressed_size as u64;
@@ -209,7 +219,7 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> {
209 name.clone(), 219 name.clone(),
210 ZipFileInfo::new( 220 ZipFileInfo::new(
211 CompressionMethod::from_struct_id(cdr.compression_method)?, 221 CompressionMethod::from_struct_id(cdr.compression_method)?,
212 BitFlag::new(cdr.bit_flag), 222 bit_flag,
213 mtime, 223 mtime,
214 atime, 224 atime,
215 ctime, 225 ctime,