TimelyDataflow / abomonation

A mortifying serialization library for Rust
MIT License
317 stars 30 forks source link

Add abomonation instance for Arc<T> #35

Open rklaehn opened 4 years ago

rklaehn commented 4 years ago

If this approach turns out to be correct, I guess we could do the same for Rc...

frankmcsherry commented 4 years ago

Hello! Sorry for the late review.

The thing that worries me here is that afaict the decode method will return a &Arc<T>, which then supports methods like clone() that return an Arc<T> without a lifetime. This returned value could then outlive the byte array on which decode was called, which could then be de-allocated, re-used, various things. I believe the Arc<T> could still have pointers in to this memory, though.

For example, in your test you could imagine decoding the Arc<String> referencing "hallo", and then cloning value2 and then writing an invalid UTF8 byte in the last position (e.g. 128). At this point I believe the clone of value2 would still be available, but reading its non-UTF8 contents would be UB.

Does that make sense to you, or should I try and modify the test to demonstrate this?