From 19ccb0807cfbb3587b1a26349112271ff00a88b7 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Thu, 10 Oct 2024 16:13:08 +0200 Subject: [PATCH] Don't do generalization on larger inptus (#2603) --- libafl/src/stages/generalization.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libafl/src/stages/generalization.rs b/libafl/src/stages/generalization.rs index 0192f7e11d..6b2d54d897 100644 --- a/libafl/src/stages/generalization.rs +++ b/libafl/src/stages/generalization.rs @@ -111,6 +111,11 @@ where let input = entry.input_mut().as_mut().unwrap(); let payload: Vec<_> = input.bytes().iter().map(|&x| Some(x)).collect(); + + if payload.len() > MAX_GENERALIZED_LEN { + return Ok(()); + } + let original = input.clone(); let meta = entry.metadata_map().get::().ok_or_else(|| { Error::key_not_found(format!( @@ -311,17 +316,15 @@ where b'"', )?; - if payload.len() <= MAX_GENERALIZED_LEN { - // Save the modified input in the corpus - { - let meta = GeneralizedInputMetadata::generalized_from_options(&payload); + // Save the modified input in the corpus + { + let meta = GeneralizedInputMetadata::generalized_from_options(&payload); - assert!(meta.generalized().first() == Some(&GeneralizedItem::Gap)); - assert!(meta.generalized().last() == Some(&GeneralizedItem::Gap)); + assert!(meta.generalized().first() == Some(&GeneralizedItem::Gap)); + assert!(meta.generalized().last() == Some(&GeneralizedItem::Gap)); - let mut entry = state.corpus().get(corpus_id)?.borrow_mut(); - entry.metadata_map_mut().insert(meta); - } + let mut entry = state.corpus().get(corpus_id)?.borrow_mut(); + entry.metadata_map_mut().insert(meta); } Ok(())