Clear stack space in BigInteger.Multiply/Square
authorStephen Toub <stoub@microsoft.com>
Sun, 6 Jan 2019 20:33:46 +0000 (15:33 -0500)
committerStephen Toub <stoub@microsoft.com>
Tue, 8 Jan 2019 14:49:59 +0000 (09:49 -0500)
Commit migrated from https://github.com/dotnet/corefx/commit/0630e45348f392a019d6b55c2100a9ee9cea8b30

src/libraries/System.Runtime.Numerics/src/System/Numerics/BigIntegerCalculator.SquMul.cs

index 7d4b5e2..f44ed20 100644 (file)
@@ -118,7 +118,9 @@ namespace System.Numerics
                 if (coreLength < AllocationThreshold)
                 {
                     uint* fold = stackalloc uint[foldLength];
+                    new Span<uint>(fold, foldLength).Clear();
                     uint* core = stackalloc uint[coreLength];
+                    new Span<uint>(core, coreLength).Clear();
 
                     // ... compute z_a = a_1 + a_0 (call it fold...)
                     Add(valueHigh, valueHighLength,
@@ -299,8 +301,11 @@ namespace System.Numerics
                 if (coreLength < AllocationThreshold)
                 {
                     uint* leftFold = stackalloc uint[leftFoldLength];
+                    new Span<uint>(leftFold, leftFoldLength).Clear();
                     uint* rightFold = stackalloc uint[rightFoldLength];
+                    new Span<uint>(rightFold, rightFoldLength).Clear();
                     uint* core = stackalloc uint[coreLength];
+                    new Span<uint>(core, coreLength).Clear();
 
                     // ... compute z_a = a_1 + a_0 (call it fold...)
                     Add(leftHigh, leftHighLength,