Skip to content

Commit

Permalink
Protect against circular type forwarders
Browse files Browse the repository at this point in the history
If we have two assemblies with type forwarders that point to each other, we enter an infinite loop and a stack overflow.

This breaks the cycle by detecting reentrancy.

Fixes #706
  • Loading branch information
KirillOsenkov committed Oct 29, 2021
1 parent a0a6ce4 commit 655d831
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Mono.Cecil/ExportedType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,21 @@ public override string ToString ()
return FullName;
}

private bool reentrancyGuard = false;

public TypeDefinition Resolve ()
{
return module.Resolve (CreateReference ());
if (reentrancyGuard) {
throw new InvalidOperationException ($"Circularity when resolving exported type {this}");
}

reentrancyGuard = true;
try {
return module.Resolve (CreateReference ());
}
finally {
reentrancyGuard = false;
}
}

internal TypeReference CreateReference ()
Expand Down

0 comments on commit 655d831

Please sign in to comment.