Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private TypeNameParser(ReadOnlySpan<char> name, bool throwOnError, TypeNameParse
{
while (TryParseNextDecorator(ref capturedBeforeProcessing, out int parsedModifier))
{
result = new(fullName: null, assemblyName, elementOrGenericType: result, rankOrModifier: (sbyte)parsedModifier);
result = new(fullName: null, assemblyName, elementOrGenericType: result, rankOrModifier: parsedModifier);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace System.Reflection.Metadata
{
internal static class TypeNameParserHelpers
{
internal const sbyte SZArray = -1;
internal const sbyte Pointer = -2;
internal const sbyte ByRef = -3;
internal const int SZArray = -1;
internal const int Pointer = -2;
internal const int ByRef = -3;
Copy link
Member Author

Choose a reason for hiding this comment

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

this change was not necessary, but since the cast to sbyte was the source of the initial bug, I wanted to remove all usages of sbyte so we use int everywhere and don't ever run into similar problem

private const char EscapeCharacter = '\\';
#if NET8_0_OR_GREATER
private static readonly SearchValues<char> s_endOfFullTypeNameDelimitersSearchValues = SearchValues.Create("[]&*,+\\");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,18 @@ public void TheNumberAfterBacktickDoesNotEnforceGenericArgCount(string input, st
Assert.Equal("bool", parsed.GetGenericArguments()[1].Name);
}

[Fact]
public void ArrayRank_SByteOverflow()
{
const string Input = "WeDontEnforceAnyMaxArrayRank[,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]";

TypeName typeName = TypeName.Parse(Input.AsSpan());

Assert.Equal(Input, typeName.FullName);
Assert.True(typeName.IsArray);
Assert.Equal(128, typeName.GetArrayRank());
}

[Theory]
[InlineData(typeof(int))]
[InlineData(typeof(int?))]
Expand Down