-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Box helpers do not handle null-valued managed pointers #70268
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Note that this might properly null-ref if JIT is optimizing (since that skips the box helper). |
They are legal, but unsafe. If you are writing unsafe code, you have to know what you are doing. I expect that there are many other places in the runtime and libraries where null managed pointers cause bad crashes. |
@jkotas, I don't think this is an acceptable stance for the runtime anymore. Things like Starting with .NET 7 and C# 11, anyone can define If it is not, then I think the language team needs to be aware and needs to have specialized handling around this scenario. |
ok, I agree that ref fields are changing the equation on this. cc @AaronRobinsonMSFT We may need to do an audit to make sure that null byrefs are handled gracefully throughout the runtime and libraries. |
Agree that dereferencing a null
I don't see how
This is a good point and we should audit the system when user-defined ByRefLike types are involved, including the cases where we may open things up to ByRefLike types in Generics. My assumption would be the platform is safe for all C# since the only types being augmented by the first phase of this work are This means we can narrow the auditing to only the IL Stub generation as the rest of the system should be well-defined. Is this a fair assessment or am I missing some nuance? |
My point was that An example of purely safe code that exposes the null byref is
I'm not so sure on this. This is functionally no different from: public ref struct ByRef<T>
{
public ref T Value;
}
object val = default(ByRef<Guid>).Value; Both should be well-defined, even if one is conceptually "unsafe". That is, not everything in With ref fields, |
@tannergooding I updated the code above to be
That is fair. Alright, I think I've got enough to look into this. Thanks all. |
The box helpers currently do not handle null refs inside of them. This should be fixed if we are making null-valued managed pointers legal (#69690). Repro:
Expected:
NullReferenceException
thrownActual:
Fatal error. Internal CLR error. (0x80131506)
The text was updated successfully, but these errors were encountered: