test: Fix bug: wrong field was being used for CRC32
This commit is contained in:
parent
d91e9ff436
commit
ede85c0f9e
3 changed files with 8 additions and 29 deletions
|
@ -13,9 +13,9 @@ pub struct UnicodeExtraField {
|
||||||
|
|
||||||
impl UnicodeExtraField {
|
impl UnicodeExtraField {
|
||||||
/// Verifies the checksum and returns the content.
|
/// Verifies the checksum and returns the content.
|
||||||
pub fn unwrap_valid(self) -> ZipResult<Box<[u8]>> {
|
pub fn unwrap_valid(self, ascii_field: &[u8]) -> ZipResult<Box<[u8]>> {
|
||||||
let mut crc32 = crc32fast::Hasher::new();
|
let mut crc32 = crc32fast::Hasher::new();
|
||||||
crc32.update(&self.content);
|
crc32.update(ascii_field);
|
||||||
let actual_crc32 = crc32.finalize();
|
let actual_crc32 = crc32.finalize();
|
||||||
if self.crc32 != actual_crc32 {
|
if self.crc32 != actual_crc32 {
|
||||||
return Err(ZipError::InvalidArchive(
|
return Err(ZipError::InvalidArchive(
|
||||||
|
|
|
@ -1285,7 +1285,7 @@ pub(crate) fn parse_single_extra_field<R: Read>(
|
||||||
// APPNOTE 4.6.8 and https://libzip.org/specifications/extrafld.txt
|
// APPNOTE 4.6.8 and https://libzip.org/specifications/extrafld.txt
|
||||||
file.file_comment = String::from_utf8(
|
file.file_comment = String::from_utf8(
|
||||||
UnicodeExtraField::try_from_reader(reader, len)?
|
UnicodeExtraField::try_from_reader(reader, len)?
|
||||||
.unwrap_valid()?
|
.unwrap_valid(file.file_comment.as_bytes())?
|
||||||
.into_vec(),
|
.into_vec(),
|
||||||
)?
|
)?
|
||||||
.into();
|
.into();
|
||||||
|
@ -1293,7 +1293,8 @@ pub(crate) fn parse_single_extra_field<R: Read>(
|
||||||
0x7075 => {
|
0x7075 => {
|
||||||
// Info-ZIP Unicode Path Extra Field
|
// Info-ZIP Unicode Path Extra Field
|
||||||
// APPNOTE 4.6.9 and https://libzip.org/specifications/extrafld.txt
|
// APPNOTE 4.6.9 and https://libzip.org/specifications/extrafld.txt
|
||||||
file.file_name_raw = UnicodeExtraField::try_from_reader(reader, len)?.unwrap_valid()?;
|
file.file_name_raw = UnicodeExtraField::try_from_reader(reader, len)?
|
||||||
|
.unwrap_valid(&file.file_name_raw)?;
|
||||||
file.file_name =
|
file.file_name =
|
||||||
String::from_utf8(file.file_name_raw.clone().into_vec())?.into_boxed_str();
|
String::from_utf8(file.file_name_raw.clone().into_vec())?.into_boxed_str();
|
||||||
file.is_utf8 = true;
|
file.is_utf8 = true;
|
||||||
|
|
28
src/write.rs
28
src/write.rs
|
@ -2584,14 +2584,13 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(not(feature = "unreserved"))]
|
#[cfg(not(feature = "unreserved"))]
|
||||||
fn test_fuzz_crash_2024_06_13() -> ZipResult<()> {
|
fn test_invalid_extra_data_unreserved() {
|
||||||
use crate::write::ExtendedFileOptions;
|
use crate::write::ExtendedFileOptions;
|
||||||
let mut writer = ZipWriter::new(Cursor::new(Vec::new()));
|
let mut writer = ZipWriter::new(Cursor::new(Vec::new()));
|
||||||
writer.set_flush_on_finish_file(false);
|
|
||||||
let options = FileOptions {
|
let options = FileOptions {
|
||||||
compression_method: Stored,
|
compression_method: Stored,
|
||||||
compression_level: None,
|
compression_level: None,
|
||||||
last_modified_time: DateTime::from_date_and_time(2021, 8, 8, 1, 0, 29)?,
|
last_modified_time: DateTime::from_date_and_time(2021, 8, 8, 1, 0, 29).unwrap(),
|
||||||
permissions: None,
|
permissions: None,
|
||||||
large_file: true,
|
large_file: true,
|
||||||
encrypt_with: None,
|
encrypt_with: None,
|
||||||
|
@ -2605,28 +2604,7 @@ mod test {
|
||||||
alignment: 4103,
|
alignment: 4103,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
writer.start_file_from_path("", options)?;
|
assert!(writer.start_file_from_path("", options).is_err());
|
||||||
let finished = writer.finish_into_readable()?;
|
|
||||||
let inner = finished.into_inner();
|
|
||||||
writer = ZipWriter::new_append(inner)?;
|
|
||||||
let options = FileOptions {
|
|
||||||
compression_method: Stored,
|
|
||||||
compression_level: None,
|
|
||||||
last_modified_time: DateTime::default(),
|
|
||||||
permissions: None,
|
|
||||||
large_file: false,
|
|
||||||
encrypt_with: None,
|
|
||||||
extended_options: ExtendedFileOptions {
|
|
||||||
extra_data: vec![].into(),
|
|
||||||
central_extra_data: vec![].into(),
|
|
||||||
},
|
|
||||||
alignment: 0,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
writer.start_file_from_path("", options)?;
|
|
||||||
writer.shallow_copy_file_from_path("", "")?;
|
|
||||||
let _ = writer.finish_into_readable()?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "deflate64")]
|
#[cfg(feature = "deflate64")]
|
||||||
|
|
Loading…
Add table
Reference in a new issue