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.rs55
1 files changed, 27 insertions, 28 deletions
diff --git a/src/zip/driver.rs b/src/zip/driver.rs
index d575509..e5aa58d 100644
--- a/src/zip/driver.rs
+++ b/src/zip/driver.rs
@@ -1,6 +1,6 @@
1use crate::driver::{ArchiveRead, ArchiveWrite, Driver}; 1use crate::driver::{ArchiveRead, ArchiveWrite, Driver};
2use crate::zip::error::{ZipError, ZipResult}; 2use crate::zip::error::{ZipError, ZipResult};
3use crate::zip::structs::{EOCDR64Locator, CDR, EOCDR, EOCDR64}; 3use crate::zip::structs::{deserialize, 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;
@@ -41,7 +41,7 @@ impl<IO: Read + Seek> ArchiveRead for Zip<IO> {
41 io.read(&mut buf)?; 41 io.read(&mut buf)?;
42 buf 42 buf
43 }; 43 };
44 let eocdr: EOCDR = bincode::deserialize(&buf).map_err(|_| ZipError::InvalidEOCDR)?; 44 let eocdr: EOCDR = deserialize(&buf).map_err(|_| ZipError::InvalidEOCDR)?;
45 let comment = { 45 let comment = {
46 let mut buf: Vec<u8> = vec![0; eocdr.comment_len as usize]; 46 let mut buf: Vec<u8> = vec![0; eocdr.comment_len as usize];
47 io.read(&mut buf)?; 47 io.read(&mut buf)?;
@@ -55,31 +55,31 @@ impl<IO: Read + Seek> ArchiveRead for Zip<IO> {
55 io.read(&mut buf)?; 55 io.read(&mut buf)?;
56 buf 56 buf
57 }; 57 };
58 let (cd_pointer, cd_size, cd_records) = 58 let (cd_pointer, cd_size, cd_records) = if u32::from_le_bytes(buf[0..4].try_into().unwrap())
59 if u32::from_le_bytes(buf[0..4].try_into().unwrap()) == 0x07064b50 { 59 == 0x07064b50
60 let eocdr64locator: EOCDR64Locator = 60 {
61 bincode::deserialize(&buf[4..]).map_err(|_| ZipError::InvalidEOCDR64Locator)?; 61 let eocdr64locator: EOCDR64Locator =
62 62 deserialize(&buf[4..]).map_err(|_| ZipError::InvalidEOCDR64Locator)?;
63 io.seek(SeekFrom::Start(eocdr64locator.eocdr64_pointer))?; 63
64 let buf = { 64 io.seek(SeekFrom::Start(eocdr64locator.eocdr64_pointer))?;
65 let mut buf = [0; 56]; 65 let buf = {
66 io.read(&mut buf)?; 66 let mut buf = [0; 56];
67 buf 67 io.read(&mut buf)?;
68 }; 68 buf
69 if u32::from_le_bytes(buf[0..4].try_into().unwrap()) != 0x06064b50 {
70 return Err(ZipError::InvalidEOCDR64Signature.into());
71 }
72 let eocdr64: EOCDR64 =
73 bincode::deserialize(&buf[4..]).map_err(|_| ZipError::InvalidEOCDR64)?;
74
75 (eocdr64.cd_pointer, eocdr64.cd_size, eocdr64.cd_records)
76 } else {
77 (
78 eocdr.cd_pointer as u64,
79 eocdr.cd_size as u64,
80 eocdr.cd_records as u64,
81 )
82 }; 69 };
70 if u32::from_le_bytes(buf[0..4].try_into().unwrap()) != 0x06064b50 {
71 return Err(ZipError::InvalidEOCDR64Signature.into());
72 }
73 let eocdr64: EOCDR64 = deserialize(&buf[4..]).map_err(|_| ZipError::InvalidEOCDR64)?;
74
75 (eocdr64.cd_pointer, eocdr64.cd_size, eocdr64.cd_records)
76 } else {
77 (
78 eocdr.cd_pointer as u64,
79 eocdr.cd_size as u64,
80 eocdr.cd_records as u64,
81 )
82 };
83 83
84 // Read cd records 84 // Read cd records
85 let mut files = Map::with_capacity(cd_records as usize); 85 let mut files = Map::with_capacity(cd_records as usize);
@@ -96,8 +96,7 @@ impl<IO: Read + Seek> ArchiveRead for Zip<IO> {
96 return Err(ZipError::InvalidCDRSignature.into()); 96 return Err(ZipError::InvalidCDRSignature.into());
97 } 97 }
98 p += 4; 98 p += 4;
99 let cdr: CDR = 99 let cdr: CDR = deserialize(&buf[p..p + 42]).map_err(|_| ZipError::InvalidCDR)?;
100 bincode::deserialize(&buf[p..p + 42]).map_err(|_| ZipError::InvalidCDR)?;
101 p += 42; 100 p += 42;
102 let name = String::from_utf8(buf[p..p + cdr.name_len as usize].into()).unwrap(); 101 let name = String::from_utf8(buf[p..p + cdr.name_len as usize].into()).unwrap();
103 p += cdr.name_len as usize; 102 p += cdr.name_len as usize;