-
Notifications
You must be signed in to change notification settings - Fork 51
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
RawWindowHandle's HasRawWindowHandle implementation is unsound #35
Comments
Far, far from an expert but if you provide a trait that provides soundness guarantees for other people to implement and document how to impl it correctly, then it's their problem if they don't impl it correctly. It's your job to try to work with both upstream and downstream to make things work but you can't force either to comply. |
No, the fault is that an implementing struct in this crate does it wrong just delete the struct. Few if any people will ever need to add this trait to their type, and they're pro enough to be able to at least read some docs. |
Is this hypothetical safety guarantee actually a practically one to begin with? What do graphics APIs do if you delete the window out from under them after setup? My intuition here is that anything working with raw window handles is necessarily unsafe. |
I think releasing 0.3.1 and yanking 0.3.0 would be acceptable if deemed necessary, but I'm not sure there are meaningful safety gains to be had, presuming that most things that take a |
The issue is that the contract so far is that by implementing the trait you're assuring that whatever you return is valid and that unsafe code can trust you since you're also unsafe code. And then this breaks that because unsafe code shouldn't generally trust safe code. |
Any guarantees you might get by that go out the window the moment you store the |
Thank you all for weighing in. I'm going to go ahead and remove the implementation in @Ralith You make some interesting points about the amount of safety this crate can conceivably provide.
I refuse to entertain this as a possibility. Windowing APIs do some questionable things, but forcibly invalidating a window handle pointer without notifying the application seems beyond the realm of sanity. That being said, @kvark Out of curiosity, does Vulkan (or any of the other graphics APIs, for that matter) specify what happens if the underlying window handle for a surface is destroyed before the corresponding graphics API surface object is destroyed? * I'd argue that it implicitly guarantees that, since handles returned by |
Not if the application explicitly deletes the window itself! Admittedly a soundness guarantee in terms of the lifetime of the handle's producer is probably still useful.
For example, the Wayland WSI states:
"must" should be read as "are unsound if failing to". |
The
impl HasRawWindowHandle for RawWindowHandle
added in #29 is a soundness hole, since it allows safe code to instantiate an invalid handle and pass it to a function that relies onHasRawWindowHandle
being implemented correctly:Removing that implementation is trivial, but there are two unresolved questions:
pub RawWindowHandleActive(RawWindowHandle)
struct that can only be initialized with an unsafe function?0.4.0
? The official Rust semver guidelines say that soundness fixes don't count as breaking changes, so I'm leaning towards no.The text was updated successfully, but these errors were encountered: