You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BigInteger.TryParse overloads accepting ReadOnlySpan<char> are ignoring the length of the span, and are reading beyond its end if there are more digits available. Here's the program to reproduce this:
using System;using System.Numerics;namespaceBigInt{publicclassProgram{publicstaticvoidMain(string[]args){vars="123456789";varspan= s.AsSpan(0,1);if(BigInteger.TryParse(span,outvar result)){
Console.WriteLine(result);}}}}
This program should be printing 1, but it's printing 123456789 instead. My running environment looks like this:
.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/
The ideal fix would likely be to no longer use pointers here and just use the ROSpan end-to-end (https://github.com/dotnet/coreclr/issues/18162). However, the short-term fix would be to just update the Number type used by BigInteger to do the same as the number type we have in corelib.
BigInteger.TryParse overloads accepting ReadOnlySpan<char> are ignoring the length of the span, and are reading beyond its end if there are more digits available. Here's the program to reproduce this:
This program should be printing 1, but it's printing 123456789 instead. My running environment looks like this:
Found via SharpFuzz.
The text was updated successfully, but these errors were encountered: