Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Most MapObservers have an unchangeable initial field #2447

Open
addisoncrump opened this issue Jul 25, 2024 · 9 comments · May be fixed by #2893
Open

Most MapObservers have an unchangeable initial field #2447

addisoncrump opened this issue Jul 25, 2024 · 9 comments · May be fixed by #2893
Labels
enhancement New feature or request

Comments

@addisoncrump
Copy link
Collaborator

This limits the relevance of the initial field. We should either make this settable (in constructor or otherwise) or remove the field.

@addisoncrump addisoncrump added cleanup Reducing our technical debt enhancement New feature or request and removed cleanup Reducing our technical debt labels Jul 25, 2024
@domenukk
Copy link
Member

What's an initial set? The initial value?

@domenukk
Copy link
Member

Probably referring to this dude

@addisoncrump
Copy link
Collaborator Author

Yeah, exactly so. "You cannot set the initial field"

@addisoncrump addisoncrump changed the title Most MapObservers cannot have initial set Most MapObservers have an unchangeable initial field Jul 26, 2024
@mzfr
Copy link
Contributor

mzfr commented Dec 28, 2024

Using something like set_initial() doesn't work because a thread could call set_initial and another thread could be calling the reset_map?

  pub fn set_initial(&mut self, initial: T) {
        self.initial = initial;
    }

If that is the case, can we just add an is_executing to the map and update it during pre_exec/post_exec, and then add support for set_initial to update only if NOT IN is_executing?

        if self.is_executing {
            Err(Error::illegal_state("Cannot update initial value during execution"))
        } else {
            self.initial = value;
            Ok(())
        }

Please let me know if I oversimplified the issue & there are other factors to consider

@tokatoka
Copy link
Member

why should it be settable? @addisoncrump

@addisoncrump
Copy link
Collaborator Author

Potentially (e.g. with min maps) there be other values to which the map is initialised. I haven't encountered this in practice, so in reality this field could probably be removed or made into a const generic.

Using something like set_initial() doesn't work because a thread could call set_initial and another thread could be calling the reset_map?

Rust guarantees that we aren't doubly-mutably accessing, I'm not sure why this would be a concern.

@tokatoka
Copy link
Member

const generic, yes.
i think nobody would want to change it after initializing

@mzfr
Copy link
Contributor

mzfr commented Dec 30, 2024

Sorry if I'm missing something but can't we just do something like:

impl<I, S, T, const INITIAL: T> Observer<I, S> for StdMapObserver<'_, T, false, INITIAL>
where
    Self: MapObserver,
{
    #[inline]
    fn pre_exec(&mut self, _state: &mut S, _input: &I) -> Result<(), Error> {
        self.reset_map()
    }
}

because rust throws an error saying

error[E0770]: the type of const parameters must not depend on other generic parameters
   --> libafl/src/observers/map/mod.rs:745:28
    |
745 | impl<'a, T, const INITIAL: T> StdMapObserver<'a, T, true, INITIAL>
    |                            ^ the type must not depend on the parameter `T`
    |

So I looked at the way StdMapObserver was used in the example fuzzers and it seemed like initial value was always 0, so u8?

Even though I tried using const INITIAL: u8, which leads to other errors. My question is, that is what you meant when you said const generics right?

@addisoncrump
Copy link
Collaborator Author

Ahh, this is actually why this was done in the first place, most likely. So there is a legitimate reason.

Instead, the with pattern (e.g., with_initial(self, initial: usize) -> Self) is a suitable alternative until const generic ADTs land.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants