This project is read-only.
1
Vote

Incorrect field offsets with array types

description

The method MemberHelper.GetFieldOffset doesn't compute the offsets correctly with fields of array types involved.

In method MemberHelper.ComputeFieldOffset, version 72407, if a field is not a nested type and not a bit field, the TypeHelper.SizeOfType function is used to compute the field size. This is obviously incorrect for reference types.

For the majority of class types, this will just waste space. But for types such as simple arrays for which TypeHelper.SizeOfType returns 0, you'll get undefined behavior since some fields will share their offsets.

I used the following code snippet to resolve the issue:
if (fieldType.IsReferenceType)
{
    fieldSize = fieldType.PlatformType.PointerSize * 8u;
}
else
{
   fieldSize = TypeHelper.SizeOfType(f.Type.ResolvedType, f.Type.ResolvedType, true) * 8;
}

comments