From: Jan Kotas Date: Thu, 27 Apr 2017 20:48:16 +0000 (-0700) Subject: Disallow conversions between Object* and Object in Array.Copy X-Git-Tag: submit/tizen/20210909.063632~11030^2~7083 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1e62dcbabe7354b6b4251006016631f255b15483;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Disallow conversions between Object* and Object in Array.Copy Fixes https://github.com/dotnet/coreclr/issues/10646 Commit migrated from https://github.com/dotnet/coreclr/commit/7c57f98183491e431ac3913d5d4b70ea82886c0a --- diff --git a/src/coreclr/src/vm/typedesc.cpp b/src/coreclr/src/vm/typedesc.cpp index d05cb55..06170cb 100644 --- a/src/coreclr/src/vm/typedesc.cpp +++ b/src/coreclr/src/vm/typedesc.cpp @@ -441,15 +441,17 @@ BOOL TypeDesc::CanCastTo(TypeHandle toType, TypeHandlePairList *pVisited) // then we must be trying to cast to a class or interface type. if (!toType.IsTypeDesc()) { - MethodTable *pMT = GetMethodTable(); - if (pMT == 0) { - // I don't have an underlying method table, therefore I'm - // a variable type, pointer type, function pointer type + if (!IsArray()) + { + // I am a variable type, pointer type, function pointer type // etc. I am not an object or value type. Therefore // I can't be cast to an object or value type. return FALSE; } + MethodTable *pMT = GetMethodTable(); + _ASSERTE(pMT != 0); + // This does the right thing if 'type' == System.Array or System.Object, System.Clonable ... if (pMT->CanCastToClassOrInterface(toType.AsMethodTable(), pVisited) != 0) { @@ -609,15 +611,17 @@ TypeHandle::CastResult TypeDesc::CanCastToNoGC(TypeHandle toType) // then we must be trying to cast to a class or interface type. if (!toType.IsTypeDesc()) { - MethodTable *pMT = GetMethodTable(); - if (pMT == 0) { - // I don't have an underlying method table, therefore I'm - // a variable type, pointer type, function pointer type + if (!IsArray()) + { + // I am a variable type, pointer type, function pointer type // etc. I am not an object or value type. Therefore // I can't be cast to an object or value type. return TypeHandle::CannotCast; } + MethodTable *pMT = GetMethodTable(); + _ASSERTE(pMT != 0); + // This does the right thing if 'type' == System.Array or System.Object, System.Clonable ... return pMT->CanCastToClassOrInterfaceNoGC(toType.AsMethodTable()); }