Skip to content

[mono] mono crash on struct copy #77588

@gemSender

Description

@gemSender

Description

mono will crash on struct copy , when struct as method parameter and parent is null.
it seems that mono use mempcy(libc) to copy value of struct without null-check on parent.

Reproduction Steps

The following simple lines of code can reproduce the problem:

using System.Collections.Generic;

public class Program
{
	struct BigStruct
    {
        public long f1;
        public long f2;
        public long f3;
        public long f4;
        public object f5;
        public object f6;
        public object f7;
		public long f8;
        public long f9;
        public long f10;
        public long f11;
		public long f12;
        public long f13;
        public long f14;
        public long f15;
    }
    
    class Holder
    {
        public BigStruct value;
    }

    private static void TestCrash(BigStruct bigStruct)
    {
		System.Console.WriteLine(bigStruct.f1 + bigStruct.f2);
    }
    public static void Main(string[] args)
    {
        List<Holder> list = new List<Holder>();
        for (int i = 0; i < 10; i++)
        {
            list.Add(null);
        }
        foreach (var holder in list)
        {
            TestCrash(holder.value);
        }
    }
}

csc Program.cs
mono Program.exe

Expected behavior

It should throw NullReferenceException rather than crash with SegmentFault

Actual behavior

crash on memcpy(libc)

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions