diff options
| author | Tolmachev Igor <me@igorek.dev> | 2024-09-02 19:54:34 +0300 |
|---|---|---|
| committer | Tolmachev Igor <me@igorek.dev> | 2024-09-02 20:27:28 +0300 |
| commit | 28208498429784f8ab9c62a12ddbf79ce8f19e4b (patch) | |
| tree | ba527ab36b5e0eeec490ed31f89baf509f6d7ccb /src/zip/driver.rs | |
| parent | dafe3b01d7dfe5f314dea37c312beae20e017f4e (diff) | |
| download | archivator-development.tar.gz archivator-development.zip | |
Add struct size constantsdevelopment
Diffstat (limited to 'src/zip/driver.rs')
| -rw-r--r-- | src/zip/driver.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/zip/driver.rs b/src/zip/driver.rs index b44c453..31f86b6 100644 --- a/src/zip/driver.rs +++ b/src/zip/driver.rs | |||
| @@ -4,7 +4,8 @@ use crate::zip::cp437::FromCp437; | |||
| 4 | use crate::zip::datetime::DosDateTime; | 4 | use crate::zip::datetime::DosDateTime; |
| 5 | use crate::zip::structs::{ | 5 | use crate::zip::structs::{ |
| 6 | deserialize, AesField, Cdr, Eocdr, Eocdr64, Eocdr64Locator, ExtraHeader, CDR_SIGNATURE, | 6 | deserialize, AesField, Cdr, Eocdr, Eocdr64, Eocdr64Locator, ExtraHeader, CDR_SIGNATURE, |
| 7 | EOCDR64_LOCATOR_SIGNATURE, EOCDR64_SIGNATURE, EOCDR_SIGNATURE, | 7 | CDR_SIZE, EOCDR64_LOCATOR_SIGNATURE, EOCDR64_LOCATOR_SIZE, EOCDR64_SIGNATURE, EOCDR64_SIZE, |
| 8 | EOCDR_SIGNATURE, EOCDR_SIZE, | ||
| 8 | }; | 9 | }; |
| 9 | use crate::zip::{ | 10 | use crate::zip::{ |
| 10 | BitFlag, CompressionMethod, EncryptionMethod, ZipError, ZipFileInfo, ZipFileReader, | 11 | BitFlag, CompressionMethod, EncryptionMethod, ZipError, ZipFileInfo, ZipFileReader, |
| @@ -91,7 +92,7 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> { | |||
| 91 | 92 | ||
| 92 | // Read eocdr | 93 | // Read eocdr |
| 93 | io.seek(SeekFrom::Start(eocdr_pos + 4))?; | 94 | io.seek(SeekFrom::Start(eocdr_pos + 4))?; |
| 94 | let buf = io.read_arr::<18>()?; | 95 | let buf = io.read_arr::<{ EOCDR_SIZE - 4 }>()?; |
| 95 | let eocdr: Eocdr = deserialize(&buf).unwrap(); | 96 | let eocdr: Eocdr = deserialize(&buf).unwrap(); |
| 96 | let comment = String::from_cp437(io.read_vec(eocdr.comment_len as usize)?); | 97 | let comment = String::from_cp437(io.read_vec(eocdr.comment_len as usize)?); |
| 97 | 98 | ||
| @@ -102,7 +103,7 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> { | |||
| 102 | // Try to find eocdr64locator | 103 | // Try to find eocdr64locator |
| 103 | if eocdr_pos >= 20 { | 104 | if eocdr_pos >= 20 { |
| 104 | io.seek(SeekFrom::Start(eocdr_pos - 20))?; | 105 | io.seek(SeekFrom::Start(eocdr_pos - 20))?; |
| 105 | let buf = io.read_arr::<20>()?; | 106 | let buf = io.read_arr::<EOCDR64_LOCATOR_SIZE>()?; |
| 106 | 107 | ||
| 107 | if buf[..4] == EOCDR64_LOCATOR_SIGNATURE { | 108 | if buf[..4] == EOCDR64_LOCATOR_SIGNATURE { |
| 108 | let locator: Eocdr64Locator = deserialize(&buf[4..]).unwrap(); | 109 | let locator: Eocdr64Locator = deserialize(&buf[4..]).unwrap(); |
| @@ -116,7 +117,8 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> { | |||
| 116 | return Err(ZipError::Overlapping("Eocdr64", "Eocdr64Locator")); | 117 | return Err(ZipError::Overlapping("Eocdr64", "Eocdr64Locator")); |
| 117 | } | 118 | } |
| 118 | 119 | ||
| 119 | let eocdr64: Eocdr64 = deserialize(&io.read_arr::<54>()?).unwrap(); | 120 | let eocdr64: Eocdr64 = |
| 121 | deserialize(&io.read_arr::<{ EOCDR64_SIZE - 4 }>()?).unwrap(); | ||
| 120 | if locator.eocdr64_pointer + eocdr64.eocdr64_size + 32 > eocdr_pos { | 122 | if locator.eocdr64_pointer + eocdr64.eocdr64_size + 32 > eocdr_pos { |
| 121 | return Err(ZipError::Overlapping("Eocdr64", "Eocdr64Locator")); | 123 | return Err(ZipError::Overlapping("Eocdr64", "Eocdr64Locator")); |
| 122 | } | 124 | } |
| @@ -148,7 +150,7 @@ impl<Io: Read + Seek> ArchiveRead for Zip<Io> { | |||
| 148 | if cd_reader.read_arr()? != CDR_SIGNATURE { | 150 | if cd_reader.read_arr()? != CDR_SIGNATURE { |
| 149 | return Err(ZipError::InvalidSignature("Cdr")); | 151 | return Err(ZipError::InvalidSignature("Cdr")); |
| 150 | } | 152 | } |
| 151 | let cdr: Cdr = deserialize(&cd_reader.read_arr::<42>()?).unwrap(); | 153 | let cdr: Cdr = deserialize(&cd_reader.read_arr::<{ CDR_SIZE - 4 }>()?).unwrap(); |
| 152 | let bit_flag = BitFlag::new(cdr.bit_flag); | 154 | let bit_flag = BitFlag::new(cdr.bit_flag); |
| 153 | 155 | ||
| 154 | let name = cd_reader.read_vec(cdr.name_len as usize)?; | 156 | let name = cd_reader.read_vec(cdr.name_len as usize)?; |
