Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FieldAccessor can't read RVA field correctly #103207

Copy link
Copy link

Description

@huoyaoyuan
Issue body actions

#102739 (comment)

var array = new int[] { 1, 2, 3, 4, 5 }; // Uses RVA field for initialization

foreach (var type in typeof(Program).Assembly.GetTypes())
{
    if (type.Name.Contains("PrivateImplementationDetails"))
    {
        foreach (var field in type.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic))
        {
            _ = field.GetValue(null);
            _ = field.GetValue(null);
        }
    }
}

Currently, the first call is correctly handled by the slow path. Subsequent calls are handled by FieldAccessor and failing. The problems are:

  • RuntimeFieldHandle.GetStaticFieldAddress is returning the RVA offset, not its address. Trying to access it will cause access violation, and translated to NullReferenceException because it's typically at page 0.
  • The managed side of FieldAccessor tries to read the field as boxed. RVA fields are not boxed.

Test is added in #102739. I'm already working on the fix.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.