Skip to content

Commit

Permalink
Preventing OverflowException when parsing scientific form of numbers. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximys committed Nov 6, 2021
1 parent 76d854d commit 494acf8
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,19 @@ private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles
{
exp = exp * 10 + (ch - '0');
ch = ++p < strEnd ? *p : '\0';
} while (ch >= '0' && ch <= '9');
} while ((ch >= '0') && (ch <= '9') && (exp < int.MaxValue / 10));

if ((ch >= '0') && (ch <= '9'))
{
// We still had remaining characters but bailed early because
// the exponent was going to overflow. If exp is exactly 214748364
// then we can technically handle one more character being 0-9
// but the additional complexity might not be worthwhile.

Debug.Assert(exp >= 214748364);
return false;
}

if (negExp)
{
exp = -exp;
Expand Down

0 comments on commit 494acf8

Please sign in to comment.