aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/zip/driver.rs38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/zip/driver.rs b/src/zip/driver.rs
index 733d44b..313bf8d 100644
--- a/src/zip/driver.rs
+++ b/src/zip/driver.rs
@@ -4,7 +4,7 @@ use crate::zip::structs::{EOCDR64Locator, CDR, EOCDR, EOCDR64};
4use crate::zip::ZipFile; 4use crate::zip::ZipFile;
5use std::collections::HashMap as Map; 5use std::collections::HashMap as Map;
6use std::fs::File; 6use std::fs::File;
7use std::io::{Read, Seek, SeekFrom, Write}; 7use std::io::{Cursor, Read, Seek, SeekFrom, Write};
8 8
9pub struct Zip<IO = File> { 9pub struct Zip<IO = File> {
10 io: IO, 10 io: IO,
@@ -89,34 +89,22 @@ impl<IO: Read + Seek> ArchiveRead for Zip<IO> {
89 io.read(&mut buf)?; 89 io.read(&mut buf)?;
90 buf 90 buf
91 }; 91 };
92 let mut records = buf.as_slice();
93 92
93 let mut p: usize = 0;
94 for _ in 0..cd_records { 94 for _ in 0..cd_records {
95 let buf = { 95 if u32::from_le_bytes(buf[p..p + 4].try_into().unwrap()) != 0x02014b50 {
96 let mut buf = [0; 46];
97 records.read(&mut buf)?;
98 buf
99 };
100
101 if u32::from_le_bytes(buf[0..4].try_into().unwrap()) != 0x02014b50 {
102 return Err(ZipError::InvalidCDRSignature.into()); 96 return Err(ZipError::InvalidCDRSignature.into());
103 } 97 }
104 let cdr: CDR = bincode::deserialize(&buf[4..]).map_err(|_| ZipError::InvalidCDR)?; 98 p += 4;
105 let name = { 99 let cdr: CDR =
106 let mut buf = vec![0; cdr.name_len as usize]; 100 bincode::deserialize(&buf[p..p + 42]).map_err(|_| ZipError::InvalidCDR)?;
107 records.read(&mut buf)?; 101 p += 42;
108 String::from_utf8(buf).map_err(|_| ZipError::InvalidFileName)? 102 let name = String::from_utf8(buf[p..p + cdr.name_len as usize].into()).unwrap();
109 }; 103 p += cdr.name_len as usize;
110 let extra_fields = { 104 let extra_fields: Vec<u8> = buf[p..p + cdr.extra_field_len as usize].into();
111 let mut buf = vec![0; cdr.extra_field_len as usize]; 105 p += cdr.extra_field_len as usize;
112 records.read(&mut buf)?; 106 let comment = String::from_utf8(buf[p..p + cdr.comment_len as usize].into()).unwrap();
113 buf 107 p += cdr.comment_len as usize;
114 };
115 let comment = {
116 let mut buf = vec![0; cdr.comment_len as usize];
117 records.read(&mut buf)?;
118 String::from_utf8(buf).map_err(|_| ZipError::InvalidFileComment)?
119 };
120 108
121 files.insert( 109 files.insert(
122 name.clone(), 110 name.clone(),