Skip to content

Commit 494acf8

Browse files
committed
Preventing OverflowException when parsing scientific form of numbers. (#17296)
1 parent 76d854d commit 494acf8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/libraries/Common/src/System/Globalization/FormatProvider.Number.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,19 @@ private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles
517517
{
518518
exp = exp * 10 + (ch - '0');
519519
ch = ++p < strEnd ? *p : '\0';
520-
} while (ch >= '0' && ch <= '9');
520+
} while ((ch >= '0') && (ch <= '9') && (exp < int.MaxValue / 10));
521+
522+
if ((ch >= '0') && (ch <= '9'))
523+
{
524+
// We still had remaining characters but bailed early because
525+
// the exponent was going to overflow. If exp is exactly 214748364
526+
// then we can technically handle one more character being 0-9
527+
// but the additional complexity might not be worthwhile.
528+
529+
Debug.Assert(exp >= 214748364);
530+
return false;
531+
}
532+
521533
if (negExp)
522534
{
523535
exp = -exp;

0 commit comments

Comments
 (0)