Skip to content

Commit

Permalink
#2767: Prevent stack overflow in Assert.Equivalent with a max travers…
Browse files Browse the repository at this point in the history
…al depth of 50 (v2)
  • Loading branch information
bradwilson committed Sep 1, 2023
1 parent 7513dbf commit c018f02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/xunit.assert/Asserts
23 changes: 23 additions & 0 deletions test/test.xunit.assert/Asserts/EquivalenceAssertsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,29 @@ public void Actual_Shallow()
}
}

public class DepthLimit
{
[Fact]
public void PreventArbitrarilyLargeDepthObjectTree()
{
var expected = new InfiniteRecursionClass();
var actual = new InfiniteRecursionClass();

var ex = Record.Exception(() => Assert.Equivalent(expected, actual));

Assert.IsType<EquivalentException>(ex);
Assert.Equal(
"Assert.Equivalent() Failure: Exceeded the maximum depth 50 with 'Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Parent'; check for infinite recursion or circular references",
ex.Message
);
}

class InfiniteRecursionClass
{
public InfiniteRecursionClass Parent => new();
}
}

public class Indexers
{
[Fact]
Expand Down

0 comments on commit c018f02

Please sign in to comment.