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

NativeAOT: Memset/Memcpy helpers don't throw NRE #95517

Closed
EgorBo opened this issue Dec 1, 2023 · 2 comments · Fixed by #98547 or #98623
Closed

NativeAOT: Memset/Memcpy helpers don't throw NRE #95517

EgorBo opened this issue Dec 1, 2023 · 2 comments · Fixed by #98547 or #98623

Comments

@EgorBo
Copy link
Member

EgorBo commented Dec 1, 2023

Compile the following program and run:

static unsafe void Main(string[] args)
{
    Unsafe.InitBlock(null, 0, 1000);
}

CoreCLR:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.

NativeAOT:

no exception, exits.

I assume this is what these comments mean:

case ReadyToRunHelper.MemCpy:
mangledName = "memcpy"; // TODO: Null reference handling
break;
case ReadyToRunHelper.MemSet:
mangledName = "memset"; // TODO: Null reference handling
break;

so I decided to file a tracking issue.

(while CoreCLR wraps memset/memcpy calls into non-inlineable/without tail calls helpers)

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 1, 2023
@ghost
Copy link

ghost commented Dec 1, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Compile the following program and run:

static unsafe void Main(string[] args)
{
    Unsafe.InitBlock(null, 0, 1000);
}

CoreCLR:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.

NativeAOT:

no exception, exits.

I assume this is what these comments mean:

case ReadyToRunHelper.MemCpy:
mangledName = "memcpy"; // TODO: Null reference handling
break;
case ReadyToRunHelper.MemSet:
mangledName = "memset"; // TODO: Null reference handling
break;

(while CoreCLR wraps memset/memcpy calls into non-inlineable/without tail calls helpers)

Author: EgorBo
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@jkotas jkotas added this to the Future milestone Dec 1, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 1, 2023
@jkotas jkotas removed the untriaged New issue has not been triaged by the area owner label Dec 1, 2023
@filipnavara
Copy link
Member

This can happen when unboxing tries to use memcpy:

struct X { int a, b, c, d, e, f, g, h, ... };
X? x = null;
object box = (object)x;
int val = (X)box;

Instead of getting a NullReferenceException it results in a crash inside memcpy with null dereference that is practically undebuggable (no stack trace available due to native code optimizations).

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 16, 2024
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 17, 2024
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 22, 2024
@EgorBo EgorBo modified the milestones: Future, 9.0.0 Feb 24, 2024
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 25, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
4 participants