refactor: Reject encrypted and using_data_descriptor files slightly faster in read_zipfile_from_stream
This commit is contained in:
parent
897cca50b3
commit
89b9b668ec
1 changed files with 9 additions and 11 deletions
20
src/read.rs
20
src/read.rs
|
@ -1361,9 +1361,14 @@ pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult<Opt
|
||||||
|
|
||||||
let version_made_by = reader.read_u16_le()?;
|
let version_made_by = reader.read_u16_le()?;
|
||||||
let flags = reader.read_u16_le()?;
|
let flags = reader.read_u16_le()?;
|
||||||
let encrypted = flags & 1 == 1;
|
if flags & 1 == 1 {
|
||||||
|
return unsupported_zip_error("Encrypted files are not supported");
|
||||||
|
}
|
||||||
|
if flags & (1 << 3) == 1 << 3 {
|
||||||
|
// using_data_descriptor flag is set
|
||||||
|
return unsupported_zip_error("The file length is not available in the local header");
|
||||||
|
}
|
||||||
let is_utf8 = flags & (1 << 11) != 0;
|
let is_utf8 = flags & (1 << 11) != 0;
|
||||||
let using_data_descriptor = flags & (1 << 3) != 0;
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
let compression_method = CompressionMethod::from_u16(reader.read_u16_le()?);
|
let compression_method = CompressionMethod::from_u16(reader.read_u16_le()?);
|
||||||
let last_mod_time = reader.read_u16_le()?;
|
let last_mod_time = reader.read_u16_le()?;
|
||||||
|
@ -1387,8 +1392,8 @@ pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult<Opt
|
||||||
let mut result = ZipFileData {
|
let mut result = ZipFileData {
|
||||||
system: System::from((version_made_by >> 8) as u8),
|
system: System::from((version_made_by >> 8) as u8),
|
||||||
version_made_by: version_made_by as u8,
|
version_made_by: version_made_by as u8,
|
||||||
encrypted,
|
encrypted: flags & 1 == 1,
|
||||||
using_data_descriptor,
|
using_data_descriptor: false,
|
||||||
compression_method,
|
compression_method,
|
||||||
compression_level: None,
|
compression_level: None,
|
||||||
last_modified_time: DateTime::from_msdos(last_mod_date, last_mod_time),
|
last_modified_time: DateTime::from_msdos(last_mod_date, last_mod_time),
|
||||||
|
@ -1421,13 +1426,6 @@ pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult<Opt
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
|
|
||||||
if encrypted {
|
|
||||||
return unsupported_zip_error("Encrypted files are not supported");
|
|
||||||
}
|
|
||||||
if using_data_descriptor {
|
|
||||||
return unsupported_zip_error("The file length is not available in the local header");
|
|
||||||
}
|
|
||||||
|
|
||||||
let limit_reader = (reader as &'a mut dyn Read).take(result.compressed_size);
|
let limit_reader = (reader as &'a mut dyn Read).take(result.compressed_size);
|
||||||
|
|
||||||
let result_crc32 = result.crc32;
|
let result_crc32 = result.crc32;
|
||||||
|
|
Loading…
Add table
Reference in a new issue