-
Notifications
You must be signed in to change notification settings - Fork 17
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
Covariance in owner is problematic / can lead to unsoundness #18
Comments
miri gives:
|
Thanks for bringing this up! It's an unlucky combination of https://users.rust-lang.org/t/can-mut-u8-being-invariant-be-observed/60135 where I switched to |
Note that covariance in the owner isn’t necessarily per say unsound; so maybe a change to rule it out entirely is more harsh than necessary. I’m not quite done trying to understand the way ouroboros does this; they seem to be using a lifetime argument in place of the Another idea is that (at least as far as the exploit in this issue is concerned), only a contravariant |
With |
I'll add an explanation of my understanding of why the code compiles shortly. |
Did some experimentation and I can only get it to work for contravariant owners. And your suggested fix:
works like a charm and even gives nice error messages:
|
interesting approach xD; I would’ve put the entire field into the Yeah, I guess that’s a good solution; just double-checked ouroboros, and it does seem like its support for contravariant types is effectively minimal and seems useless, so no major loss here :-) |
The important thing to note is that So fn helper<'b>(s: &'b str) -> impl for<'a> FnOnce(&'a fn(&'b ())) -> &'a str is effectively something like fn helper<'b>(s: &'b str) -> impl for<'a, where 'b: 'a> FnOnce(&'a fn(&'b ())) -> &'a str because without
And that’s the problem with a contravariant lifetime in the owner. Your |
I plan on implementing this fix proper with testing soon. |
This addresses issue #18 where a contravariant owner could lead to UB.
This addresses issue #18 where a contravariant owner could lead to UB.
Looks decent, I guess. |
The text was updated successfully, but these errors were encountered: