Skip to content

Reduce algorithmic complexity for parsing If-Match and If-None-Match. - #66796

Merged
cincuranet merged 15 commits into
dotnet:mainfrom
cincuranet:if-match2
Jun 15, 2026
Merged

cincuranet merged 15 commits into
dotnet:mainfrom
cincuranet:if-match2

Conversation

@cincuranet

Copy link
Copy Markdown
Contributor

Fixes #66668

@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label May 22, 2026

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 reduces worst-case parsing complexity for malformed If-Match / If-None-Match entity tag lists by propagating consumed malformed spans and advancing recovery by that span instead of retrying one character at a time.

Changes:

  • Extends internal parser contracts to return parsedLength on success and failure.
  • Propagates consumed lengths from malformed quoted entity tags through range/entity tag parsing.
  • Adds a regression test ensuring pathological unterminated quoted strings are parsed in one attempt.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Shared/HttpRuleParser.cs Reports consumed length for invalid unterminated expressions.
src/Http/Headers/src/HttpHeaderParser.cs Updates parser contract and recovery loops to advance by consumed length.
src/Http/Headers/src/BaseHeaderParser.cs Implements consumed-length propagation for generic header parsers.
src/Http/Headers/src/EntityTagHeaderValue.cs Propagates malformed quoted-string length for entity tags.
src/Http/Headers/src/RangeConditionHeaderValue.cs Handles malformed consumed entity tags without producing a value.
src/Http/Headers/src/CookieHeaderParser.cs Adapts cookie parsing to the new consumed-length contract.
src/Http/Headers/src/CacheControlHeaderValue.cs Updates parser call sites and internal list parsing advancement.
src/Http/Headers/src/ContentDispositionHeaderValue.cs Updates TryParse call site.
src/Http/Headers/src/ContentRangeHeaderValue.cs Updates TryParse call site.
src/Http/Headers/src/CookieHeaderValue.cs Updates TryParse call site.
src/Http/Headers/src/MediaTypeHeaderValue.cs Updates TryParse call site.
src/Http/Headers/src/NameValueHeaderValue.cs Updates TryParse call site.
src/Http/Headers/src/RangeHeaderValue.cs Updates TryParse call site.
src/Http/Headers/src/SetCookieHeaderValue.cs Updates TryParse call site.
src/Http/Headers/src/StringWithQualityHeaderValue.cs Updates TryParse call site.
src/Http/Headers/test/EntityTagHeaderValueTest.cs Adds regression coverage for the pathological entity tag input.

@cincuranet cincuranet self-assigned this Jun 1, 2026
@cincuranet

Copy link
Copy Markdown
Contributor Author

/ba-g Failures are unrelated.

@cincuranet
cincuranet merged commit ac7fe7d into dotnet:main Jun 15, 2026
20 of 25 checks passed
@cincuranet
cincuranet deleted the if-match2 branch June 15, 2026 07:23
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High algorithmic complexity when parsing If-Match or If-None-Match header values containing many comma separators followed by an unparseable character

4 participants