AFLplusplus / AFLplusplus/LibAFL

Make `current_corpus_idx` infallible?

Offen
#2,200 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
2.6k
Forks
481
Ø Merge
2 T. 30 Min.
Gemergte PRs (30 T.)
16

Beschreibung

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!

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.