Bug fix in Arbitrary impl

This commit is contained in:
Chris Hennick 2023-05-13 14:04:17 -07:00
parent 429b5dfa0b
commit d53d2d61b6
No known key found for this signature in database
GPG key ID: 25653935CC8B6C74

View file

@ -142,14 +142,14 @@ pub struct FileOptions {
impl arbitrary::Arbitrary for FileOptions { impl arbitrary::Arbitrary for FileOptions {
fn arbitrary(u: &mut Unstructured) -> arbitrary::Result<Self> { fn arbitrary(u: &mut Unstructured) -> arbitrary::Result<Self> {
let mut options = FileOptions { let mut options = FileOptions {
compression_method: CompressionMethod::arbitrary(&mut u), compression_method: CompressionMethod::arbitrary(&mut u)?,
compression_level: Option::<CompressionLevel>::arbitrary(&mut u), compression_level: Option::<CompressionLevel>::arbitrary(&mut u)?,
last_modified_time: DateTime::arbitrary(&mut u), last_modified_time: DateTime::arbitrary(&mut u)?,
permissions: Option::<u32>::arbitrary(&mut u), permissions: Option::<u32>::arbitrary(&mut u)?,
large_file: bool::arbitrary(&mut u), large_file: bool::arbitrary(&mut u)?,
encrypt_with: Option::<ZipCryptoKeys>::arbitrary(&mut u), encrypt_with: Option::<ZipCryptoKeys>::arbitrary(&mut u)?,
extra_data: Vec::with_capacity(u16::MAX as usize), extra_data: Vec::with_capacity(u16::MAX as usize)?,
central_extra_data: Vec::with_capacity(u16::MAX as usize), central_extra_data: Vec::with_capacity(u16::MAX as usize)?,
}; };
#[derive(arbitrary::Arbitrary)] #[derive(arbitrary::Arbitrary)]
struct ExtraDataField { struct ExtraDataField {
@ -157,12 +157,12 @@ impl arbitrary::Arbitrary for FileOptions {
data: Vec<u8>, data: Vec<u8>,
central_only: bool, central_only: bool,
} }
let extra_data = Vec::<ExtraDataField>::arbitrary(&mut u); let extra_data = Vec::<ExtraDataField>::arbitrary(&mut u)?;
for field in extra_data { for field in extra_data {
let _ = let _ =
options.add_extra_data(field.header_id, field.data.as_slice(), field.central_only); options.add_extra_data(field.header_id, field.data.as_slice(), field.central_only);
} }
options Ok(options)
} }
} }