Mirror Windows behavior for managed HttpListener Content-Length #130910
Open
iremyux wants to merge 1 commit into
Open
Mirror Windows behavior for managed HttpListener Content-Length #130910iremyux wants to merge 1 commit into
iremyux wants to merge 1 commit into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
iremyux
enabled auto-merge (squash)
July 16, 2026 19:17
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes the managed (System.Net.Managed) HttpListener request header parsing to treat out-of-range Content-Length values as invalid (i.e., parse failure) rather than accepting them and normalizing certain overflow cases to 0, aligning the managed behavior with the Windows implementation’s strict decimal parsing shape.
Changes:
- Updated managed
Content-Lengthparsing to uselong.TryParse(..., NumberStyles.None, InvariantCulture, ...)and reject parse failures. - Moved coverage for overflow
Content-Lengthvalues from “property returns 0” semantics to “invalid client request” semantics (400 Bad Request). - Adjusted tests to keep the valid upper bound (
long.MaxValue) case while removing the previous “overflow => 0” expectations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Net.HttpListener/tests/InvalidClientRequestTests.cs | Adds invalid-request cases asserting Bad Request for Content-Length values beyond long.MaxValue. |
| src/libraries/System.Net.HttpListener/tests/HttpListenerRequestTests.cs | Removes prior expectations that overflow Content-Length values are treated as 0. |
| src/libraries/System.Net.HttpListener/src/System/Net/Managed/HttpListenerRequest.Managed.cs | Switches to strict long.TryParse-based Content-Length parsing and rejects out-of-range values. |
Open
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aligns managed HttpListener Content-Length parsing behavior with Windows behavior by rejecting out-of-range numeric values instead of treating certain overflow values as zero.