Skip to content
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

Emit a null check when loading valuetype fields #1853

Merged
merged 1 commit into from Oct 13, 2023
Merged

Conversation

bholmes
Copy link
Member

@bholmes bholmes commented Oct 5, 2023

We had a similar bug with stfld recently.
#1781
dotnet/runtime#82663

  • Should this pull request have release notes?
    • Yes
    • No
  • Do these changes need to be back ported?
    • Yes
    • No
  • Do these changes need to be upstreamed to mono/mono or dotnet/runtime repositories?
    • Yes
    • No

Release notes

Fixed UUM-47983 @bholmes :
Mono: Fix runtime crash when accessing a struct field of a null object.

Backports

  • 2022.3
  • 2023.1
  • 2023.2
  • 2023.3

@bholmes
Copy link
Member Author

bholmes commented Oct 5, 2023

The test I used to debug this

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

public class Program
{
    public Program()
    {
    }

    static int Main(string[] args)
    {
        Foo defaultFoo = default;
        //GetBar().foo = defaultFoo;
        //defaultFoo = GetBar().foo;
        new Bar().foo =  GetBar().foo;
        return 0;
    }

    static Bar GetBar()
    {
        return null;
    }
}

public class Bar
{
    public Foo foo = default;
}

[StructLayout(LayoutKind.Explicit)]
public unsafe struct Foo
{
    [FieldOffset(0)] public object obj;
    [FieldOffset(8)] public fixed long Value[32];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants