Uri.TryCreate is a non-throwing method, but for some inputs it can throw IndexOutOfRangeException. Here's the full program that reproduces this:
using System;
using System.Text;
namespace Test
{
public class Program
{
public static void Main(string[] args)
{
var b = new byte[] {
92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92,
92, 226, 128, 174, 47, 255, 11, 117, 102, 112, 10
};
var s = Encoding.UTF8.GetString(b);
Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out _);
}
}
}
The stack trace:
Exception has occurred: CLR/System.IndexOutOfRangeException
An unhandled exception of type 'System.IndexOutOfRangeException' occurred in System.Private.Uri.dll: '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.CreateHelper(String uriString, Boolean dontEscape, UriKind uriKind, UriFormatException& e)
at System.Uri.TryCreate(String uriString, UriKind uriKind, Uri& result)
The environment:
.NET Core SDK (reflecting any global.json):
Version: 2.2.103
Commit: 8edbc2570a
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.14
OS Platform: Darwin
RID: osx.10.14-x64
Base Path: /usr/local/share/dotnet/sdk/2.2.103/
Found via SharpFuzz.
Uri.TryCreate is a non-throwing method, but for some inputs it can throw IndexOutOfRangeException. Here's the full program that reproduces this:
The stack trace:
The environment:
Found via SharpFuzz.