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 (v3)
  • Loading branch information
bradwilson committed Aug 31, 2023
1 parent 966a5b7 commit ffeeed6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/xunit.v3.assert.tests/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
2 changes: 1 addition & 1 deletion src/xunit.v3.assert/Asserts

0 comments on commit ffeeed6

Please sign in to comment.