chore: Fix boxed_local warning (can borrow instead)
This commit is contained in:
parent
cbb180a316
commit
94df73ea04
3 changed files with 38 additions and 12 deletions
|
@ -620,7 +620,7 @@ impl ZipFileData {
|
||||||
aes_extra_data_start: u64,
|
aes_extra_data_start: u64,
|
||||||
compression_method: crate::compression::CompressionMethod,
|
compression_method: crate::compression::CompressionMethod,
|
||||||
aes_mode: Option<(AesMode, AesVendorVersion, CompressionMethod)>,
|
aes_mode: Option<(AesMode, AesVendorVersion, CompressionMethod)>,
|
||||||
extra_field: Box<[u8]>,
|
extra_field: &[u8],
|
||||||
) -> Self
|
) -> Self
|
||||||
where
|
where
|
||||||
S: Into<Box<str>>,
|
S: Into<Box<str>>,
|
||||||
|
|
44
src/write.rs
44
src/write.rs
|
@ -339,8 +339,8 @@ impl ExtendedFileOptions {
|
||||||
let header_id = data.read_u16_le()?;
|
let header_id = data.read_u16_le()?;
|
||||||
if header_id <= 31
|
if header_id <= 31
|
||||||
|| EXTRA_FIELD_MAPPING
|
|| EXTRA_FIELD_MAPPING
|
||||||
.iter()
|
.iter()
|
||||||
.any(|&mapped| mapped == header_id)
|
.any(|&mapped| mapped == header_id)
|
||||||
{
|
{
|
||||||
return Err(ZipError::Io(io::Error::new(
|
return Err(ZipError::Io(io::Error::new(
|
||||||
io::ErrorKind::Other,
|
io::ErrorKind::Other,
|
||||||
|
@ -871,9 +871,8 @@ impl<W: Write + Seek> ZipWriter<W> {
|
||||||
let mut aes_extra_data_start = 0;
|
let mut aes_extra_data_start = 0;
|
||||||
#[cfg(feature = "aes-crypto")]
|
#[cfg(feature = "aes-crypto")]
|
||||||
if let Some(EncryptWith::Aes { mode, .. }) = options.encrypt_with {
|
if let Some(EncryptWith::Aes { mode, .. }) = options.encrypt_with {
|
||||||
let aes_dummy_extra_data = vec![
|
let aes_dummy_extra_data =
|
||||||
0x02, 0x00, 0x41, 0x45, mode as u8, 0x00, 0x00,
|
vec![0x02, 0x00, 0x41, 0x45, mode as u8, 0x00, 0x00].into_boxed_slice();
|
||||||
].into_boxed_slice();
|
|
||||||
extensions.add_extra_data(0x9901, aes_dummy_extra_data, false)?;
|
extensions.add_extra_data(0x9901, aes_dummy_extra_data, false)?;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -896,7 +895,7 @@ impl<W: Write + Seek> ZipWriter<W> {
|
||||||
aes_extra_data_start,
|
aes_extra_data_start,
|
||||||
compression_method,
|
compression_method,
|
||||||
aes_mode,
|
aes_mode,
|
||||||
extensions.extra_data.to_vec().into_boxed_slice(),
|
&extensions.extra_data,
|
||||||
);
|
);
|
||||||
parse_extra_field(&mut file)?;
|
parse_extra_field(&mut file)?;
|
||||||
file.version_made_by = file.version_made_by.max(file.version_needed() as u8);
|
file.version_made_by = file.version_made_by.max(file.version_needed() as u8);
|
||||||
|
@ -926,7 +925,6 @@ impl<W: Write + Seek> ZipWriter<W> {
|
||||||
}
|
}
|
||||||
let header_end = writer.stream_position()?;
|
let header_end = writer.stream_position()?;
|
||||||
|
|
||||||
|
|
||||||
file.extra_data_start = Some(writer.stream_position()?);
|
file.extra_data_start = Some(writer.stream_position()?);
|
||||||
let mut extra_data_end = header_end + extensions.extra_data.len() as u64;
|
let mut extra_data_end = header_end + extensions.extra_data.len() as u64;
|
||||||
if options.alignment > 1 {
|
if options.alignment > 1 {
|
||||||
|
@ -2633,12 +2631,25 @@ mod test {
|
||||||
#[cfg(feature = "deflate64")]
|
#[cfg(feature = "deflate64")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fuzz_crash_2024_06_13a() -> ZipResult<()> {
|
fn test_fuzz_crash_2024_06_13a() -> ZipResult<()> {
|
||||||
use CompressionMethod::Deflate64;
|
|
||||||
use crate::write::ExtendedFileOptions;
|
use crate::write::ExtendedFileOptions;
|
||||||
|
use CompressionMethod::Deflate64;
|
||||||
|
|
||||||
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);
|
writer.set_flush_on_finish_file(false);
|
||||||
let options = FileOptions { compression_method: Deflate64, compression_level: None, last_modified_time: DateTime::from_date_and_time(2039, 4, 17, 6, 18, 19)?, permissions: None, large_file: true, encrypt_with: None, extended_options: ExtendedFileOptions {extra_data: vec![].into(), central_extra_data: vec![].into()}, alignment: 4, ..Default::default() };
|
let options = FileOptions {
|
||||||
|
compression_method: Deflate64,
|
||||||
|
compression_level: None,
|
||||||
|
last_modified_time: DateTime::from_date_and_time(2039, 4, 17, 6, 18, 19)?,
|
||||||
|
permissions: None,
|
||||||
|
large_file: true,
|
||||||
|
encrypt_with: None,
|
||||||
|
extended_options: ExtendedFileOptions {
|
||||||
|
extra_data: vec![].into(),
|
||||||
|
central_extra_data: vec![].into(),
|
||||||
|
},
|
||||||
|
alignment: 4,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
writer.add_directory_from_path("", options)?;
|
writer.add_directory_from_path("", options)?;
|
||||||
let _ = writer.finish_into_readable()?;
|
let _ = writer.finish_into_readable()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -2652,7 +2663,20 @@ mod test {
|
||||||
let sub_writer = {
|
let sub_writer = {
|
||||||
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);
|
writer.set_flush_on_finish_file(false);
|
||||||
let options = FileOptions { compression_method: Stored, compression_level: None, last_modified_time: DateTime::from_date_and_time(1980, 4, 14, 6, 11, 54)?, permissions: None, large_file: false, encrypt_with: None, extended_options: ExtendedFileOptions {extra_data: vec![].into(), central_extra_data: vec![].into()}, alignment: 185, ..Default::default() };
|
let options = FileOptions {
|
||||||
|
compression_method: Stored,
|
||||||
|
compression_level: None,
|
||||||
|
last_modified_time: DateTime::from_date_and_time(1980, 4, 14, 6, 11, 54)?,
|
||||||
|
permissions: None,
|
||||||
|
large_file: false,
|
||||||
|
encrypt_with: None,
|
||||||
|
extended_options: ExtendedFileOptions {
|
||||||
|
extra_data: vec![].into(),
|
||||||
|
central_extra_data: vec![].into(),
|
||||||
|
},
|
||||||
|
alignment: 185,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
writer.add_symlink_from_path("", "", options)?;
|
writer.add_symlink_from_path("", "", options)?;
|
||||||
writer
|
writer
|
||||||
};
|
};
|
||||||
|
|
|
@ -128,7 +128,9 @@ fn write_test_archive(file: &mut Cursor<Vec<u8>>, method: CompressionMethod, sha
|
||||||
zip.start_file("test/☃.txt", options.clone()).unwrap();
|
zip.start_file("test/☃.txt", options.clone()).unwrap();
|
||||||
zip.write_all(b"Hello, World!\n").unwrap();
|
zip.write_all(b"Hello, World!\n").unwrap();
|
||||||
|
|
||||||
options.add_extra_data(0xbeef, EXTRA_DATA.to_owned().into_boxed_slice(), false).unwrap();
|
options
|
||||||
|
.add_extra_data(0xbeef, EXTRA_DATA.to_owned().into_boxed_slice(), false)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
zip.start_file("test_with_extra_data/🐢.txt", options)
|
zip.start_file("test_with_extra_data/🐢.txt", options)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue