From 64a29c55f3604a310891195be5203b5262159077 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 22:41:28 +0000 Subject: [PATCH 1/2] Initial plan From 91d31dbd7a933ebf1dbbea80dd508566448ce87b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 27 May 2026 22:58:39 +0000 Subject: [PATCH 2/2] Add regression test for JsonSerializer.Deserialize MaxDepth with deeply nested arrays Co-authored-by: steveisok <471438+steveisok@users.noreply.github.com> --- .../Serialization/DomTests.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/DomTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/DomTests.cs index bf11f1cbf8b875..c98e0f91d7c628 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/DomTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/DomTests.cs @@ -210,6 +210,26 @@ public static void SerializeToNode_RespectsMaxDepth(int maxDepth) Assert.Throws(() => JsonSerializer.SerializeToNode(value, options)); } + [Theory] + [InlineData(5)] + [InlineData(32)] + [InlineData(70)] // default max depth is 64 + public static void DeserializeToNode_RespectsMaxDepth(int maxDepth) + { + var options = new JsonSerializerOptions { MaxDepth = maxDepth }; + + // Deserializing JSON at exactly the max depth should succeed. + string validJson = string.Concat(Enumerable.Repeat("[", maxDepth)) + + string.Concat(Enumerable.Repeat("]", maxDepth)); + JsonNode? node = JsonSerializer.Deserialize(validJson, options); + Assert.NotNull(node); + + // Deserializing JSON exceeding the max depth by one should throw. + string tooDeepJson = string.Concat(Enumerable.Repeat("[", maxDepth + 1)) + + string.Concat(Enumerable.Repeat("]", maxDepth + 1)); + Assert.Throws(() => JsonSerializer.Deserialize(tooDeepJson, options)); + } + public class RecursiveClass { public RecursiveClass? Next { get; set; }