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
{{ message }}
Repository navigation
BigInteger correctness regression from .NET 8 #109669
In my understanding, it affects the operators &, |, ^ whose result is a negative number of the form -2^(32n), n>1. In other words, whose result is 0xFFFFFFFF 00000000 ... 00000000 for any positive number of trailing zero blocks, such that the length of the two's complement of this value is greater than the number of trailing zero blocks.
An assert can fire for values with nonzero trailing blocks, but it does not result in correctness issues. But for the affected values, it can also give rise to an exception when formatting, because of invalid internal state e.g.
BigIntegera=newBigInteger(MemoryMarshal.AsBytes([uint.MaxValue,0u,0u]),isBigEndian:true);BigIntegeror=a|a;Console.WriteLine(or==a);// False (should be True)Console.WriteLine(or);// System.IndexOutOfRangeException: Index was outside the bounds of the array.// at System.Number.FormatBigInteger(Boolean targetSpan, BigInteger value, String formatString, ReadOnlySpan`1 formatSpan, NumberFormatInfo info, Span`1 destination, Int32& charsWritten, Boolean& spanSuccess)// at System.Number.FormatBigInteger(BigInteger value, String format, NumberFormatInfo info)// at System.Numerics.BigInteger.ToString()
Activity
dotnet-policy-service commentedon Nov 9, 2024
Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.
[-]BigInteger regression from .NET 8[/-][+]BigInteger correctness regression from .NET 8[/+]tannergooding commentedon Nov 9, 2024
Bug looks to be in the internal span constructor and sign preservation being incorrectly tracked as
false.jeffhandley commentedon Nov 9, 2024
Thanks for reporting this, @hez2010. We will fix this and backport into 9.0 servicing.
@tannergooding Do you think this is limited to a small domain of values? We will need to prepare a Known Issues entry on https://github.com/dotnet/core/blob/main/release-notes/9.0/known-issues.md for this.
Rob-Hague commentedon Nov 10, 2024
In my understanding, it affects the operators
&,|,^whose result is a negative number of the form -2^(32n), n>1. In other words, whose result is 0xFFFFFFFF 00000000 ... 00000000 for any positive number of trailing zero blocks, such that the length of the two's complement of this value is greater than the number of trailing zero blocks.An assert can fire for values with nonzero trailing blocks, but it does not result in correctness issues. But for the affected values, it can also give rise to an exception when formatting, because of invalid internal state e.g.
huoyaoyuan commentedon Nov 10, 2024
The fix was already submitted at #105456