From e91cbf40efb743a859646e841ea168599dbd957e Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Wed, 28 Nov 2018 03:54:12 -0800 Subject: Fixing up Utf8Parser.TryParseNumber to not fail for overly large exponents (#21233) --- .../System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs b/src/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs index daa1da60a8..799a3fe6a7 100644 --- a/src/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs +++ b/src/System.Private.CoreLib/shared/System/Buffers/Text/Utf8Parser/Utf8Parser.Number.cs @@ -303,10 +303,15 @@ namespace System.Buffers.Text { if (number.Scale > int.MaxValue - (long)absoluteExponent) { - bytesConsumed = 0; - return false; + // A scale overflow means all non-zero digits are all so far to the right of the decimal point, no + // number format we have will be able to see them. Just pin the scale at the absolute maximum + // and let the converter produce a 0 with the max precision available for that type. + number.Scale = int.MaxValue; + } + else + { + number.Scale += (int)absoluteExponent; } - number.Scale += (int)absoluteExponent; } digits[dstIndex] = 0; -- cgit v1.2.3