-
-
Notifications
You must be signed in to change notification settings - Fork 330
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
SerdeAnyMap: add unsafe_stable_anymap
feature that uses type_name
instead of TypeId::of
#1952
Conversation
unsafe_stable_anymap
feature that uses type_name
instead of TypeId::of
@addisoncrump just how stupid of an idea is this? |
Since we already require |
Ah, actually, it theoretically could be problematic if the type names (not including the crate path) are exactly the same, but I'm quite certain this won't happen in practice. |
If they are all |
Sad, doesn't seem to work: error: lifetime may not live long enough
--> libafl_bolts/src/serdeany.rs:143:21
|
132 | impl<'de> serde::de::Visitor<'de> for BoxDynVisitor {
| --- lifetime `'de` defined here
...
143 | let id: TypeRepr = visitor.next_element()?.unwrap();
| ^^^^^^^^ type annotation requires that `'de` must outlive `'static`
error: lifetime may not live long enough
--> libafl_bolts/src/serdeany.rs:227:9
|
225 | #[derive(Debug, Serialize, Deserialize)]
| ----------- lifetime `'de` defined here
226 | pub struct SerdeAnyMap {
227 | map: HashMap<TypeRepr, Box<dyn SerdeAny>>,
| ^^^ requires that `'de` must outlive `'static`
error: lifetime may not live long enough
--> libafl_bolts/src/serdeany.rs:424:9
|
422 | #[derive(Debug, Serialize, Deserialize)]
| ----------- lifetime `'de` defined here
423 | pub struct NamedSerdeAnyMap {
424 | map: HashMap<TypeRepr, HashMap<u64, Box<dyn crate::serdeany::SerdeAny>>>,
| ^^^ requires that `'de` must outlive `'static` |
We can manually impl Deserialize here. |
Static lifetime means that, if I own the value, it will live for as long as I hold it. It doesn't guarantee that these values will be in the same place between executions, so we can't serialize them as &'static str. Instead, we'll need to manually deserialise to match the entries in the local registry. |
Actually, we can do a sneaky and impl Deserialize for a wrapper type around the TypeRepr to simplify this. |
Do you want to give it a shot? |
Sure, I'll take a crack at it now. |
Can you commit the non-working code? I'll fix it from there. |
I just replaced String with |
@@ -98,7 +140,7 @@ pub mod serdeany_registry { | |||
where | |||
V: serde::de::SeqAccess<'de>, | |||
{ | |||
let id: u128 = visitor.next_element()?.unwrap(); | |||
let id: TypeRepr = visitor.next_element()?.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addisoncrump I'm not 100% sure if this type annotation is correct (or should be borrowed or something?)
@addisoncrump just open a new PR if you manage to do it with 'static str somehow |
While technically unsound, this just might give us a build-agnostic anymap which would pre pretty nice to have to store and load state.
/edit: fixes #1374