[reflection] mono_method_get_base_method on a GTD should use canonical ginst (mono...
authorAleksey Kliger (λgeek) <alklig@microsoft.com>
Tue, 22 Oct 2019 18:07:44 +0000 (14:07 -0400)
committerGitHub <noreply@github.com>
Tue, 22 Oct 2019 18:07:44 +0000 (14:07 -0400)
commit3cef24a08c5567039e102321efa773aad5b3dc9b
tree4ecfc58b1a96fa578162d4fec5b8fc160edd2f34
parent5dc174ed5ce7e6d1c7c3c69708ccdeb6415507d2
[reflection] mono_method_get_base_method on a GTD should use canonical ginst (mono/mono#17475)

* [test] GetCustomAttributes on generic type definition

* [reflection] mono_method_get_base_method on a GTD should use canonical ginst

The issue is in how we pass along the generic instantiation.  So there are two
parts here: we start with a method on a GTD which has to decompose into the GTD
and it's instantiation with its own generic parameters, and then we go up to
its parent and grandparent inflating and decomposing the resulting
instantiation. The instantiations keep passing the last parameter as the number
of parameters shrinks so that the gparam index from the original type is now
out of bounds for the parent and grandparent.  If we mess up, we'll get a
BadImageFormatException from the runtime

Fixes https://github.com/mono/mono/issues/17278

Commit migrated from https://github.com/mono/mono/commit/fb5b2c949ddd2ab09fcddb458584a5facd9ec94e
src/mono/mono/metadata/class.c