Skip to content

Conversation

@MihaZupan
Copy link
Member

If Compress removes the entire path, and that path was otherwise missing a leading slash, we can get into the case where dest.Length == start after the Compress call.
This triggers a debug assert in the ValueStringBuilder's this[] accessor since we're reading past the length, but it's actually harmless in practice in this case since the underlying buffer will always have at least 1 available character after start on this path (note the dest.Length - offset > 0 condition before compression).

@MihaZupan MihaZupan added this to the 11.0.0 milestone Jan 9, 2026
@MihaZupan MihaZupan self-assigned this Jan 9, 2026
Copilot AI review requested due to automatic review settings January 9, 2026 23:14
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

nice.

@MihaZupan MihaZupan enabled auto-merge (squash) January 9, 2026 23:21
Copy link
Contributor

Copilot AI left a comment

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 fixes a debug assertion failure in Uri path canonicalization that occurs when the Compress method removes an entire path that was missing a leading slash. The fix adds a bounds check before accessing the character at the start position.

  • Adds bounds check (dest.Length > start) before accessing dest[start] to prevent reading past buffer length
  • Adds braces for consistency with coding style
  • Includes a test case that reproduces the edge case scenario

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Private.Uri/src/System/Uri.cs Adds bounds check and braces to prevent out-of-bounds access when path compression removes entire path
src/libraries/System.Private.Uri/tests/FunctionalTests/UriRelativeResolutionTest.cs Adds test case for FTP URI where entire path can be removed by compression

@MihaZupan MihaZupan merged commit 53653bd into dotnet:main Jan 10, 2026
94 of 97 checks passed
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