mardi 10 juillet 2018

FieldInfo.GetValue() can crash your program; how does one avoid this?

It appears that certain calls to FieldInfo.GetValue() can outright crash your program with some versions of Mono/.NET (or at least the Mono version packaged with Unity).

Specifically, when given an instance of System.Globalization.CultureInfo, attempting to evaluate the field "Systen.Int32* calendar_data" using FieldInfo.GetValue() will cause the process to crash. This is the stack trace:

0x00007FFC0A6A3C58 (KERNELBASE) RaiseException 0x00007FFBDCFD1158 (mono) [c:\buildslave\mono\build\eglib\src\goutput.c:201] g_logv 0x00007FFBDCFD117C (mono) [c:\buildslave\mono\build\eglib\src\goutput.c:211] g_log 0x00007FFBDD04E223 (mono) [c:\buildslave\mono\build\mono\metadata\object.c:2945] mono_field_get_value_object 0x000000001179273B (Mono JIT Code) (wrapper managed-to-native) System.Reflection.MonoField:GetValueInternal (object) 0x00000000117924D6 (Mono JIT Code) [/Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoField.cs:118] System.Reflection.MonoField:GetValue (object)

Also, a call to FieldInfo.GetValue on an instance of Mono.Globalization.Unicode.SimpleCollator caused a similar crash, although the exact evaluated member could not be determined.

I'm trying to figure out if there is a pattern to crashes caused by FieldInfo.GetValue calls, I.E. what calls will crash the program and which ones won't.

Any namespace named Globalization seems to contain classes prone to making reflection crashy, but I doubt that's the cause.

DoesFieldInfo.GetValue() try to return the object pointed to by a pointer? This would be pretty bizzare as you'd expect it to return a memory address (e.g. IntPtr) given that it is a pointer type, otherwise it'd be impossible to null check the pointer. Nonetheless I can skip pointer fields if it prevents a crash.





Aucun commentaire:

Enregistrer un commentaire