style: Cargo fmt --all
This commit is contained in:
parent
e3c81023a7
commit
7530ce5000
2 changed files with 21 additions and 14 deletions
|
@ -1,14 +1,14 @@
|
|||
use core::mem::size_of;
|
||||
use std::io::Read;
|
||||
use crate::result::{ZipError, ZipResult};
|
||||
use crate::unstable::LittleEndianReadExt;
|
||||
use core::mem::size_of;
|
||||
use std::io::Read;
|
||||
|
||||
/// Info-ZIP Unicode Path Extra Field (0x7075) or Unicode Comment Extra Field (0x6375), as
|
||||
/// specified in APPNOTE 4.6.8 and 4.6.9
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UnicodeExtraField {
|
||||
crc32: u32,
|
||||
content: Box<[u8]>
|
||||
content: Box<[u8]>,
|
||||
}
|
||||
|
||||
impl<'a> UnicodeExtraField {
|
||||
|
@ -18,7 +18,9 @@ impl<'a> UnicodeExtraField {
|
|||
crc32.update(ascii_field);
|
||||
let actual_crc32 = crc32.finalize();
|
||||
if self.crc32 != actual_crc32 {
|
||||
return Err(ZipError::InvalidArchive("CRC32 checksum failed on Unicode extra field"));
|
||||
return Err(ZipError::InvalidArchive(
|
||||
"CRC32 checksum failed on Unicode extra field",
|
||||
));
|
||||
}
|
||||
Ok(self.content)
|
||||
}
|
||||
|
@ -30,11 +32,9 @@ impl UnicodeExtraField {
|
|||
reader.read_exact(&mut [0u8])?;
|
||||
|
||||
let crc32 = reader.read_u32_le()?;
|
||||
let mut content = vec![0u8; len as usize - size_of::<u8>() - size_of::<u32>()].into_boxed_slice();
|
||||
let mut content =
|
||||
vec![0u8; len as usize - size_of::<u8>() - size_of::<u32>()].into_boxed_slice();
|
||||
reader.read_exact(&mut content)?;
|
||||
Ok(Self {
|
||||
crc32,
|
||||
content
|
||||
})
|
||||
Ok(Self { crc32, content })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
15
src/read.rs
15
src/read.rs
|
@ -95,6 +95,7 @@ pub(crate) mod zip_archive {
|
|||
|
||||
#[cfg(feature = "aes-crypto")]
|
||||
use crate::aes::PWD_VERIFY_LENGTH;
|
||||
use crate::extra_fields::UnicodeExtraField;
|
||||
#[cfg(feature = "lzma")]
|
||||
use crate::read::lzma::LzmaDecoder;
|
||||
use crate::result::ZipError::{InvalidPassword, UnsupportedArchive};
|
||||
|
@ -102,7 +103,6 @@ use crate::spec::{is_dir, path_to_string};
|
|||
use crate::types::ffi::S_IFLNK;
|
||||
use crate::unstable::LittleEndianReadExt;
|
||||
pub use zip_archive::ZipArchive;
|
||||
use crate::extra_fields::UnicodeExtraField;
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub(crate) enum CryptoReader<'a> {
|
||||
|
@ -1286,15 +1286,22 @@ fn parse_extra_field(file: &mut ZipFileData) -> ZipResult<()> {
|
|||
// APPNOTE 4.6.8 and https://libzip.org/specifications/extrafld.txt
|
||||
if !file.is_utf8 {
|
||||
file.file_comment = String::from_utf8(
|
||||
UnicodeExtraField::try_from_reader(&mut reader, len)?.unwrap_valid(file.file_comment.as_bytes())?.into_vec())?.into();
|
||||
UnicodeExtraField::try_from_reader(&mut reader, len)?
|
||||
.unwrap_valid(file.file_comment.as_bytes())?
|
||||
.into_vec(),
|
||||
)?
|
||||
.into();
|
||||
}
|
||||
}
|
||||
0x7075 => {
|
||||
// Info-ZIP Unicode Path Extra Field
|
||||
// APPNOTE 4.6.9 and https://libzip.org/specifications/extrafld.txt
|
||||
if !file.is_utf8 {
|
||||
file.file_name_raw = UnicodeExtraField::try_from_reader(&mut reader, len)?.unwrap_valid(&file.file_name_raw)?;
|
||||
file.file_name = String::from_utf8(file.file_name_raw.clone().into_vec())?.into_boxed_str();
|
||||
file.file_name_raw = UnicodeExtraField::try_from_reader(&mut reader, len)?
|
||||
.unwrap_valid(&file.file_name_raw)?;
|
||||
file.file_name =
|
||||
String::from_utf8(file.file_name_raw.clone().into_vec())?.into_boxed_str();
|
||||
file.is_utf8 = true;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
|
Loading…
Add table
Reference in a new issue