Skip to content

Mirror Windows behavior for managed HttpListener Content-Length #130910

Open
iremyux wants to merge 1 commit into
dotnet:mainfrom
iremyux:reject-content-length
Open

Mirror Windows behavior for managed HttpListener Content-Length #130910
iremyux wants to merge 1 commit into
dotnet:mainfrom
iremyux:reject-content-length

Conversation

@iremyux

@iremyux iremyux commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

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.

@iremyux
iremyux requested a review from MihaZupan July 16, 2026 19:16
@iremyux iremyux self-assigned this Jul 16, 2026
Copilot AI review requested due to automatic review settings July 16, 2026 19:16
@azure-pipelines

Copy link
Copy Markdown
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
iremyux enabled auto-merge (squash) July 16, 2026 19:17
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-Length parsing to use long.TryParse(..., NumberStyles.None, InvariantCulture, ...) and reject parse failures.
  • Moved coverage for overflow Content-Length values 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants