-
Notifications
You must be signed in to change notification settings - Fork 13
Clone for UnionN
is unsound with malicious P: ErasablePtr + Clone
#89
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
Comments
Yet another good find, thank you! It's a little unfortunate to add overhead and a panic opportunity to (The only saving grace is that allocations tend to be aligned to That's also the failing that incorrectly tried to justify the current implementation — in the first draft, having If you write a patch I should hopefully be able to push an update the following day (US Eastern). If you don't, hopefully I can do it myself on this weekend. |
If you don't mind me asking, how'd you come across this? I honestly thought I hardened all these crates pretty well, but it's been a pretty while. As a side note, my bar for quality has gone up since I first wrote these crates, and I really should write a successor crate (tentatively named pointrs; ptrs got taken) that's more up to my modern standards. I've just justified waiting so far on every attempt1 to improve the core design of the (erasable) pointer abstraction wanting for the lack of feature(ptr_metadata), or at least Footnotes
|
Sure, I can make a PR to fix this.
There was some functionality that I wanted (a Visitor api) but I wasn't sure if it was sound. I also wanted to see if I could support an arbitrary number of types (if you had sufficient alignment on the pointers). So I made my own implementation, and while comparing implementations to make sure I didn't screw up somewhere I noticed this
Yeah, I'm also eagerly awaiting
Me too! (as you may have guessed from my story above) |
Fix published in v2.3.0 |
Uh oh!
There was an error while loading. Please reload this page.
Currently
ErasablePtr
doesn't require thatClone
preserves that the pointer is aligned. So it's possible to construct a type like thishttps://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=292dca0467b3b0e1e8514b98087dc0c7
In particular in affects
impl Clone for UnionN
pointer-utils/crates/ptr-union/src/lib.rs
Line 561 in 26c260e
since here it's assumed that
Clone
will always return an aligned pointer.So either
ErasablePtr
needs to be updated to include this, orUnionN
needs to check that the cloned pointers are aligned.The text was updated successfully, but these errors were encountered: