Fix max input size for {CrossOverInsert,BytesInsertCopy}Mutator (#1097)

This commit is contained in:
Mrmaxmeier 2023-02-24 00:07:54 +01:00 committed by GitHub
parent 64a57ad3e3
commit ff4e2f4192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -818,12 +818,14 @@ where
_stage_idx: i32, _stage_idx: i32,
) -> Result<MutationResult, Error> { ) -> Result<MutationResult, Error> {
let size = input.bytes().len(); let size = input.bytes().len();
if size <= 1 { if size <= 1 || size == state.max_size() {
return Ok(MutationResult::Skipped); return Ok(MutationResult::Skipped);
} }
let target = state.rand_mut().below(size as u64) as usize; let target = state.rand_mut().below(size as u64) as usize;
let range = rand_range(state, size, size - target); // make sure that the sampled range is both in bounds and of an acceptable size
let max_insert_len = min(size - target, state.max_size() - size);
let range = rand_range(state, size, max_insert_len);
self.tmp_buf.clear(); self.tmp_buf.clear();
self.tmp_buf.extend(input.bytes()[range].iter().copied()); self.tmp_buf.extend(input.bytes()[range].iter().copied());
@ -959,7 +961,7 @@ where
return Ok(MutationResult::Skipped); return Ok(MutationResult::Skipped);
} }
let range = rand_range(state, other_size, min(other_size, max_size - size + 1)); let range = rand_range(state, other_size, min(other_size, max_size - size));
let target = state.rand_mut().below(size as u64) as usize; let target = state.rand_mut().below(size as u64) as usize;
let mut other_testcase = state.corpus().get(idx)?.borrow_mut(); let mut other_testcase = state.corpus().get(idx)?.borrow_mut();