AFLplusplus / AFLplusplus/LibAFL

Make `current_corpus_idx` infallible?

Abierto
#2,200 3 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Rust
Estrellas
2.6k
Forks
481
Merge medio
2 d 30 min
PR fusionados (30 d)
16

Descripción

Currently, [`current_corpus_idx`](https://github.com/AFLplusplus/LibAFL/blob/0777873aaef62e309075cb4b64ef04e0b0124afe/libafl/src/corpus/mod.rs#L186) returns an `Option`. However, most places where `current_(testcase|corpus_idx)` are called don't meaningfully handle it returning `None`, instead just propagating the error. In most fuzzers, we'd actually expect the `None`-handling branch to be dead code. I wonder if there's a way to *actually* make this method infallible. Hopefully this could even result in some performance gains by eliminating these branches? The revised trait would look like this:
```rust
/// Trait for types which track the current corpus index
pub trait HasCurrentCorpusIdx {
/// Set the current corpus index; we have started processing this corpus entry
fn set_corpus_idx(&mut self, idx: CorpusId) -> Result<(), Error>;

/// Fetch the current corpus index
fn current_corpus_idx(&self) -> Result;
}
```
The difficulty is that the `State` would have to choose an initial index *at the time it is constructed* (probably using a `Scheduler`). Right now, we generally construct `State`s before loading/generating the initial corpus. Perhaps there's some kind of type-state pattern, like there could be an `InitialStdState` that doesn't implement `HasCurrentCorpusIdx`, but has methods to load/generate the initial corpus *and* pick an initial index, and they all return `StdState` (which *would* implement the infallible version of `HasCurrentCorpusIdx`).

Just an idea :shrug: Feel free to close if not helpful!

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.