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 jbevain#706
  • Loading branch information
KirillOsenkov committed Oct 15, 2023
1 parent 56d4409 commit 5ad5672
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 5ad5672

Please sign in to comment.