-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
UpgradedSendStream transmute seems to be super unsound #3500
Comments
For historical reference, this was discussed in #2831 and determined it wasn't unsound. Could be we got it wrong in there, I'm just including it for context. |
Yeah, that discussion seems to focus on whether |
Also stepping back a bit this pattern here is extremely weird and has almost no comments explaining what it does or justifying its safety. It's worth considering moving away from this model anyway, if possible. |
cc @nox, you'll remember this better than I. |
Agreed. |
There is no such thing as “not include it as a discriminant choice” as that would be an observable behaviour for repr(usize) and break things related to such enums. Servo for example include uninhabited variants in repr(u32) enums specifically to skip a few variant discriminants to make the actually inhabited variants have their discriminants coincide with other enums. See discussions on the explicit discriminants Rust RFC. I am on PTO with a smartphone with a broken screen so you’ll excuse me for the lack of links in this comment hopefully.
Ven 22 déc 2023, à 16:09, Ralf Jung a écrit :
…
> There's nothing preventing the compiler from realizing that Buf(Neutered<...>) is impossible and deciding to not include it as a discriminant choice. The asserts in this code are insufficient to check that.
>
Agreed.
—
Reply to this email directly, view it on GitHub <#3500 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAA6BV6JLBF3EMSPAHMNBULYKWPDNAVCNFSM6AAAAABA6V6R4SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNRXG44TKMZZGI>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Ah sorry I had missed that this enum is |
@RalfJung does that also work with the transitivity assumption? |
Not sure which assumption exactly you mean? Basically the question is, for two Whether that's actually implemented properly for uninhabited types (rust-lang/unsafe-code-guidelines#485), I don't know. |
Okay, good to know, thanks! |
So did that extra information mean that this is fine after all? Or do we need to adjust something? |
I think it's still potentially an issue given:
but the bigger issue is a non-issue it seems. |
https://github.com/hyperium/hyper/blob/1d4ff3597b8e76818c8553dbfa4234cf4208c958/src/proto/h2/mod.rs#L389C8-L397
This isn't sound.
Neutered<B>
is:Firstly, it's unclear what guarantees
repr(transparent)
confers here,impossible
does havesize_of == 0
but it's not exactly a zero-sized type (rust-lang/unsafe-code-guidelines#485). Therepr(transparent)
RFC is not clear about this, and it's quite shaky ground to rely on, especially since empty ("impossible") types are one place Rust does sometimes perform layout optimizations. There's an assertion guard against that forNeutered
but it's not clear how transitive this stuff is (rust-lang/unsafe-code-guidelines#486)Empty types can and do affect enum representations.
SendBuf<B>
has the following definition:There's nothing preventing the compiler from realizing that
Buf(Neutered<...>)
is impossible and deciding to not include it as a discriminant choice. The asserts in this code are insufficient to check that.This code seems to work fine under the current compiler but I wouldn't rely on that.
The text was updated successfully, but these errors were encountered: