diff --git a/libafl/src/corpus/cached.rs b/libafl/src/corpus/cached.rs index c3fbee79d4..3b2f10857c 100644 --- a/libafl/src/corpus/cached.rs +++ b/libafl/src/corpus/cached.rs @@ -107,9 +107,8 @@ where self.inner.replace(idx, testcase) } - /// Removes an entry from the corpus, returning it if it was present. - #[inline] - fn remove(&mut self, idx: CorpusId) -> Result, Error> { + /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases. + fn remove(&mut self, idx: CorpusId) -> Result, Error> { let testcase = self.inner.remove(idx)?; self.cached_indexes.borrow_mut().retain(|e| *e != idx); Ok(testcase) diff --git a/libafl/src/corpus/inmemory.rs b/libafl/src/corpus/inmemory.rs index 88e4abd187..8ada3b2149 100644 --- a/libafl/src/corpus/inmemory.rs +++ b/libafl/src/corpus/inmemory.rs @@ -396,12 +396,14 @@ where .ok_or_else(|| Error::key_not_found(format!("Index {idx} not found"))) } - /// Removes an entry from the corpus, returning it if it was present. + /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases #[inline] - fn remove(&mut self, idx: CorpusId) -> Result, Error> { - self.storage - .enabled - .remove(idx) + fn remove(&mut self, idx: CorpusId) -> Result, Error> { + let mut testcase = self.storage.enabled.remove(idx); + if testcase.is_none() { + testcase = self.storage.disabled.remove(idx); + } + testcase .map(|x| x.take()) .ok_or_else(|| Error::key_not_found(format!("Index {idx} not found"))) } diff --git a/libafl/src/corpus/inmemory_ondisk.rs b/libafl/src/corpus/inmemory_ondisk.rs index f9bcebd942..e69eeb6b57 100644 --- a/libafl/src/corpus/inmemory_ondisk.rs +++ b/libafl/src/corpus/inmemory_ondisk.rs @@ -112,7 +112,7 @@ where Ok(entry) } - /// Removes an entry from the corpus, returning it if it was present. + /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled corpus #[inline] fn remove(&mut self, idx: CorpusId) -> Result, Error> { let entry = self.inner.remove(idx)?; diff --git a/libafl/src/corpus/mod.rs b/libafl/src/corpus/mod.rs index 63e1a67ba7..edf47fe5b5 100644 --- a/libafl/src/corpus/mod.rs +++ b/libafl/src/corpus/mod.rs @@ -113,7 +113,7 @@ pub trait Corpus: UsesInput + Serialize + for<'de> Deserialize<'de> { testcase: Testcase, ) -> Result, Error>; - /// Removes an entry from the corpus, returning it if it was present. + /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases fn remove(&mut self, id: CorpusId) -> Result, Error>; /// Get by id; considers only enabled testcases diff --git a/libafl/src/corpus/nop.rs b/libafl/src/corpus/nop.rs index cf0437c043..b7d668fd27 100644 --- a/libafl/src/corpus/nop.rs +++ b/libafl/src/corpus/nop.rs @@ -63,7 +63,7 @@ where Err(Error::unsupported("Unsupported by NopCorpus")) } - /// Removes an entry from the corpus, returning it if it was present. + /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases #[inline] fn remove(&mut self, _idx: CorpusId) -> Result, Error> { Err(Error::unsupported("Unsupported by NopCorpus")) diff --git a/libafl/src/corpus/ondisk.rs b/libafl/src/corpus/ondisk.rs index 4f8512e9c5..82cdd2cee5 100644 --- a/libafl/src/corpus/ondisk.rs +++ b/libafl/src/corpus/ondisk.rs @@ -112,7 +112,7 @@ where self.inner.peek_free_id() } - /// Removes an entry from the corpus, returning it if it was present. + /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases #[inline] fn remove(&mut self, idx: CorpusId) -> Result, Error> { self.inner.remove(idx)