From 7d5fbcd04b3acf9fa31619437118595e22ebbe8d Mon Sep 17 00:00:00 2001 From: alinpahontu2912 Date: Fri, 14 Aug 2026 16:18:30 +0200 Subject: [PATCH] Guard oversized Content-Length test cases for managed HttpListener only InvalidRequest_TestData fed two new POST cases with Content-Length values above long.MaxValue directly into GetContext_InvalidRequest_DoesNotGetContext, which also runs against the native http.sys-backed HttpListenerRequest.Windows.cs on Windows. http.sys does not reject these oversized values the same way the managed parser (HttpListenerRequest.Managed.cs) now does, so the server never completes the request and the test hangs until the Helix executor timeout kills the work item. Wrap the two new test cases in an 'if (Helpers.IsManagedImplementation)' guard, matching the existing pattern used elsewhere in this file, so they only run against the managed implementation whose behavior they were written to verify. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bcc5e304-cc27-44b0-aac3-b9eada42d13f --- .../tests/InvalidClientRequestTests.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Net.HttpListener/tests/InvalidClientRequestTests.cs b/src/libraries/System.Net.HttpListener/tests/InvalidClientRequestTests.cs index a9703669b6bdbc..8c8ba02de4b8e3 100644 --- a/src/libraries/System.Net.HttpListener/tests/InvalidClientRequestTests.cs +++ b/src/libraries/System.Net.HttpListener/tests/InvalidClientRequestTests.cs @@ -74,8 +74,11 @@ public static IEnumerable InvalidRequest_TestData() yield return new object[] { "GET {path} HTTP/1.1", null, new string[] { "Content-Length: -9223372036854775809" }, "\r\n", "Bad Request" }; yield return new object[] { "GET {path} HTTP/1.1", null, new string[] { "Content-Length: 1", "Content-Length: 2" }, "\r\n", "Bad Request" }; - yield return new object[] { "POST {path} HTTP/1.1", null, new string[] { "Content-Length: 9223372036854775808" }, "\r\n", "Bad Request" }; // long.MaxValue + 1 - yield return new object[] { "POST {path} HTTP/1.1", null, new string[] { "Content-Length: 18446744073709551615" }, "\r\n", "Bad Request" }; // ulong.MaxValue + if (Helpers.IsManagedImplementation) + { + yield return new object[] { "POST {path} HTTP/1.1", null, new string[] { "Content-Length: 9223372036854775808" }, "\r\n", "Bad Request" }; // long.MaxValue + 1 + yield return new object[] { "POST {path} HTTP/1.1", null, new string[] { "Content-Length: 18446744073709551615" }, "\r\n", "Bad Request" }; // ulong.MaxValue + } yield return new object[] { "GET {path} HTTP/1.1", null, new string[] { "Transfer-Encoding: garbage" }, "\r\n", "Not Implemented" }; yield return new object[] { "POST {path} HTTP/1.1", null, new string[] { "Transfer-Encoding: garbage" }, "\r\n", "Not Implemented" };