Make sure input was loaded to avoid panic on unwrap in MutatedTransform (#1077)

* make sure input was loaded to avoid panic on unwrap
fixes issue #1059

* avoid unnecessary clone, avoid unnecessary branching

---------

Co-authored-by: Michael Rodler <m@mrodler.eu>
Co-authored-by: Addison Crump <addison.crump@cispa.de>
This commit is contained in:
Michael Rodler 2023-02-16 17:29:33 +01:00 committed by GitHub
parent f454d17482
commit 46b75747ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -108,7 +108,7 @@ where
type Post = Self;
fn try_transform_from(
base: &Testcase<BytesInput>,
base: &mut Testcase<BytesInput>,
_state: &S,
corpus_idx: CorpusId,
) -> Result<Self, Error> {

View File

@ -51,7 +51,7 @@ where
/// Transform the provided testcase into this type
fn try_transform_from(
base: &Testcase<I>,
base: &mut Testcase<I>,
state: &S,
corpus_idx: CorpusId,
) -> Result<Self, Error>;
@ -69,11 +69,11 @@ where
#[inline]
fn try_transform_from(
base: &Testcase<I>,
base: &mut Testcase<I>,
_state: &S,
_corpus_idx: CorpusId,
) -> Result<Self, Error> {
Ok(base.input().as_ref().unwrap().clone())
Ok(base.load_input()?.clone())
}
#[inline]
@ -116,8 +116,8 @@ where
let num = self.iterations(state, corpus_idx)?;
start_timer!(state);
let testcase = state.corpus().get(corpus_idx)?.borrow();
let Ok(input) = I::try_transform_from(&testcase, state, corpus_idx) else { return Ok(()); };
let mut testcase = state.corpus().get(corpus_idx)?.borrow_mut();
let Ok(input) = I::try_transform_from(&mut testcase, state, corpus_idx) else { return Ok(()); };
drop(testcase);
mark_feature_time!(state, PerfFeature::GetInputFromCorpus);

View File

@ -82,8 +82,8 @@ where
) -> Result<(), Error> {
let num = self.iterations(state, corpus_idx)?;
let testcase = state.corpus().get(corpus_idx)?.borrow();
let Ok(input) = I::try_transform_from(&testcase, state, corpus_idx) else { return Ok(()); };
let mut testcase = state.corpus().get(corpus_idx)?.borrow_mut();
let Ok(input) = I::try_transform_from(&mut testcase, state, corpus_idx) else { return Ok(()); };
drop(testcase);
for i in 0..num {