AFLplusplus / AFLplusplus/LibAFL

Make `current_corpus_idx` infallible?

Đang mở
#2,200 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
2.6k
Fork
481
Merge trung bình
2 ngày 30 phút
Pull request đã merge (30 ngày)
16

Mô tả

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!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.