Skip to content

Commit b3060d8

Browse files
authored
Merge pull request #567 from ElektroKill/fix/TryGetOriginalTargetFrameworkAttribute
Fix potential infinite loop in `TryGetOriginalTargetFrameworkAttribute`
2 parents c78d296 + a606e38 commit b3060d8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/DotNet/AssemblyDef.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,21 @@ void InitializeTargetFrameworkAttribute() {
901901
var caRid = list[i];
902902
if (!readerModule.TablesStream.TryReadCustomAttributeRow(caRid, out var caRow))
903903
continue;
904+
905+
// Prevent a possible infinite loop.
906+
// This can happen when a custom AssemblyResolver calls this function when resolving an AssemblyRef.
907+
// If this function encounters a custom attribute whose type is a MemberRef with a TypeSpec class,
908+
// the MemberRef constructor called by ResolveCustomAttributeType() will call ResolveTypeDef() which
909+
// will make it back to the AssemblyResolver and back to this function creating an infinite loop.
910+
// The TargetFrameworkAttribute will never be generic so we can just skip parsing any generic attributes.
911+
if (!CodedToken.CustomAttributeType.Decode(caRow.Type, out MDToken token))
912+
continue;
913+
if (token.Table == Table.MemberRef &&
914+
(!readerModule.TablesStream.TryReadMemberRefRow(token.Rid, out var mrRow) ||
915+
readerModule.ResolveMemberRefParent(mrRow.Class, gpContext) is TypeSpec ts &&
916+
ts.TypeSig is GenericInstSig))
917+
continue;
918+
904919
var caType = readerModule.ResolveCustomAttributeType(caRow.Type, gpContext);
905920
if (!TryGetName(caType, out var ns, out var name))
906921
continue;

0 commit comments

Comments
 (0)