-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Description
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 toNullReferenceException
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.