Skip to content

[Uri] Uri(String, UriKind) throws IndexOutOfRangeException for certain inputs #1487

Closed

Description

@davkean

We're relying on Uri in the http://github.com/dotnet/project-system, to represent paths. Testing our path handling code, I found that Uri throws IndexOutOfRangeException (instead of UriFormatException) in the following situations:

new Uri("/\\‎//", UriKind.Absolute);
new Uri("\\/\u200e", UriKind.Absolute);
new Uri("/\\\\-Ā\r", UriKind.Absolute);
new Uri("\\\\\\\\\\‎", UriKind.Absolute);

Activity

  1. danmoseley commented on Jun 19, 2017

    @danmoseley
    Contributor

    @davkean none of these throw anything (including UFE) on Desktop for me..?

    Clearly this isa bug though as they throw IOORE on Core.

    Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
       at System.Uri.CreateUriInfo(Flags cF)
       at System.Uri.EnsureUriInfo()
       at System.Uri.ParseRemaining()
       at System.Uri.EnsureParseRemaining()
       at System.Uri.InitializeUri(ParsingError err, UriKind uriKind, UriFormatException& e)
       at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
       at System.Uri..ctor(String uriString, UriKind uriKind)
       at ConsoleApp1.Program.Main(String[] args) in C:\dotnet\1\Program.cs:line 13
    

    @karelz is this the right label for Uri? Please consider whether this is a 2.0 issue.

  2. danmoseley commented on Jun 19, 2017

    @danmoseley
    Contributor
  3. danmoseley commented on Jun 19, 2017

    @danmoseley
    Contributor

    My guess: these are not mainstream enough cases to churn Uri further for 2.0.

  4. karelz commented on Jun 19, 2017

    @karelz
    Member

    It's a good label. @Priya91 can you please help with this one?

  5. Priya91 commented on Jun 19, 2017

    @Priya91
    Contributor

    @davkean These are invalid URIs? Will look into this.

  6. davkean commented on Jun 19, 2017

    @davkean
    MemberAuthor

    @danmosemsft Are you testing under 4.5+? Uri was changed in 4.5. I just verified and they all repro for me under desktop.

    @Priya91 TBH, I've not done the legwork to figure out if they are invalid according to spec - they were generated for me by Pex. I don't need them for 2.0.

  7. danmoseley commented on Jun 19, 2017

    @danmoseley
    Contributor

    @davkean ah, no I used csc out of the v4.0 folder...

  8. davkean commented on Jun 19, 2017

    @davkean
    MemberAuthor

    Yeah, you'll go down the 4.0 path.

  9. karelz commented on Jun 22, 2017

    @karelz
    Member

    Does not look like 2.0 bug, moving to Future for further consideration.

  10. rmkerr commented on May 2, 2018

    @rmkerr
    Contributor

    It looks like all of these are failing because they contain the Unicode LTR control character. Historically we have stripped control characters out of URIs, and that behavior is causing the issue here. We calculate the index of the end of the path and then strip out the control character, shortening the string and causing the index to fall beyond the end of the string.

    The fix here is non-trivial, as the change will have to be made to some fairly complex unsafe code. I'll keep the issue assigned to me but don't have an ETA on this.

  11. changed the title [-]Uri(String, UriKind) throws IndexOutOfRangeException for certain inputs[/-] [+][Uri] Uri(String, UriKind) throws IndexOutOfRangeException for certain inputs[/+] on May 2, 2018
  12. self-assigned this
    on May 2, 2018
  13. davidsh commented on Aug 28, 2019

    @davidsh
    Contributor

    As of .NET Core 3.0 Preview 8 these

    new Uri("/\\‎//", UriKind.Absolute);
    new Uri("\\/\u200e", UriKind.Absolute);
    new Uri("\\\\\\\\\\‎", UriKind.Absolute);

    are still throwing IndexOutOfRangeException. So, we still have a bug to fix.

  14. transferred this issue fromdotnet/corefxon Jan 9, 2020
  15. 12 remaining items

  16. dotnet-policy-service commented on Mar 5, 2025

    @dotnet-policy-service
    Contributor

    This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

  17. removed this from the Future milestone on Mar 5, 2025
  18. removed
    backlog-cleanup-candidate
    on Mar 6, 2025
  19. added this to the Future milestone on Mar 6, 2025
  20. added
    in-pr
    on Oct 27, 2025
  21. modified the milestones: Future, 11.0.0 on Nov 24, 2025
  22. locked and limited conversation to collaborators on Dec 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Netbugin-pr

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions