Copilot commented on code in PR #546:
URL: https://github.com/apache/arrow-dotnet/pull/546#discussion_r4808756204


##########
test/Apache.Arrow.Tests/DecimalUtilityTests.cs:
##########
@@ -188,6 +189,68 @@ private void TestFromString(string s, int precision, int 
scale, int byteWidth, s
                 Assert.Equal(result, DecimalUtility.GetString(new 
ArrowBuffer(bytes), 0, precision, scale, byteWidth));
             }
 
+            // The precision and scale come from the type, which may come from 
untrusted data, so
+            // they must not decide how much stack is used.
+            [Theory]
+            [InlineData(100_000_000)]
+            [InlineData(int.MaxValue)]
+            public void ToStringWithAHugePrecision(int precision)
+            {
+                foreach (int byteWidth in new[] { 4, 8, 16, 32 })
+                {
+                    var bytes = new byte[byteWidth];
+                    DecimalUtility.GetBytes(-100.12m, 9, 2, byteWidth, bytes);
+                    Assert.Equal("-100.12", DecimalUtility.GetString(new 
ArrowBuffer(bytes), 0, precision, 2, byteWidth));
+                }
+            }
+
+            [Theory]
+            [InlineData(4)]
+            [InlineData(8)]
+            [InlineData(16)]
+            [InlineData(32)]
+            public void ToStringOfTheLargestValuesWithAHugePrecision(int 
byteWidth)
+            {
+                var largest = new byte[byteWidth];
+                largest.AsSpan().Fill(0xFF);
+                largest[byteWidth - 1] = 0x7F;
+                var smallest = new byte[byteWidth];
+                smallest[byteWidth - 1] = 0x80;
+
+                foreach (byte[] bytes in new[] { largest, smallest })
+                {
+                    string digits = new BigInteger(bytes).ToString();
+                    string expected = digits.Substring(0, digits.Length - 1) + 
"." + digits.Substring(digits.Length - 1);
+                    Assert.Equal(expected, DecimalUtility.GetString(new 
ArrowBuffer(bytes), 0, int.MaxValue, 1, byteWidth));
+                }
+            }
+
+            [Fact]
+            public void ToStringWithAHugeScale()
+            {
+                const int scale = 1_000_000;
+                foreach (int byteWidth in new[] { 4, 8, 16, 32 })
+                {
+                    var bytes = new byte[byteWidth];
+                    bytes[0] = 1;
+                    string expected = "0." + new string('0', scale - 1) + "1";
+                    Assert.Equal(expected, DecimalUtility.GetString(new 
ArrowBuffer(bytes), 0, 10, scale, byteWidth));
+                }
+            }
+
+            [Theory]
+            [InlineData(100_000_000)]
+            [InlineData(int.MaxValue - 10)]
+            public void FromStringWithAHugePrecision(int precision)
+            {
+                foreach (int byteWidth in new[] { 4, 8, 16, 32 })
+                {
+                    var bytes = new byte[byteWidth];
+                    DecimalUtility.GetBytes("-100.12", precision, 3, 
byteWidth, bytes);
+                    Assert.Equal("-100.120", DecimalUtility.GetString(new 
ArrowBuffer(bytes), 0, 10, 3, byteWidth));
+                }
+            }

Review Comment:
   The new parsing test needs only eight buffer characters, leaving the 
heap-allocation path and `ParseBufferLength` overflow guard untested. Add cases 
around the 256-character boundary and at scale 1,000,000, covering both zero 
padding and a long fractional input across all four byte widths. Also verify 
that parsing "0" with `int.MaxValue` scale throws `OverflowException`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to