-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Closed
Copy link
Labels
area-System.Runtimein-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Description
Description
Convert.TryToHexString{Lower} will allow the destination that smaller than actual length and will NOT allow what is bigger than 2x actual length.
Reproduction Steps
Span<byte> hashBuffer = stackalloc byte[16];
Span<char> biggerThanDoubleLength = stackalloc char[33];
Debug.Assert(Convert.TryToHexString(hashBuffer, biggerThanDoubleLength, out _) == false);
Span<char> lessThanLength = stackalloc char[31];
Debug.Assert(Convert.TryToHexStringLower(hashBuffer, lessThanLength, out var length));
Debug.Assert(length == 32);
Console.WriteLine("done");
Expected behavior
The function may return false when the size of destination is smaller than 2x source and working when destination is bigger than 2x source.
Actual behavior
The function will return true when the size of destination is smaller than 2x source with proper out variable charsWritten and will NOT working when destination is bigger than 2x source.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
It look like 2 variable is reversed.
| else if (source.Length > int.MaxValue / 2 || destination.Length > source.Length * 2) |
| else if (source.Length > int.MaxValue / 2 || destination.Length > source.Length * 2) |
0xfeeddeadbeef
Metadata
Metadata
Assignees
Labels
area-System.Runtimein-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged