1
0
Fork 0
mirror of https://github.com/ultrajson/ultrajson.git synced 2024-05-27 13:06:21 +02:00

Merge pull request #442 from dwhswenson/fix_large_floats

This commit is contained in:
Hugo van Kemenade 2020-11-16 15:43:14 +02:00 committed by GitHub
commit 7cceea1bba
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -90,6 +90,7 @@ static FASTCALL_ATTR JSOBJ FASTCALL_MSVC decodeDouble(struct DecoderState *ds)
static FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric (struct DecoderState *ds)
{
int intNeg = 1;
int hasError = 0;
JSUINT64 intValue;
JSUINT64 prevIntValue;
int chr;
@ -130,11 +131,11 @@ static FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric (struct DecoderState *ds
if (intNeg == 1 && prevIntValue > intValue)
{
return SetError(ds, -1, "Value is too big!");
hasError = 1;
}
else if (intNeg == -1 && intValue > overflowLimit)
{
return SetError(ds, -1, overflowLimit == LLONG_MAX ? "Value is too big!" : "Value is too small");
hasError = 1;
}
offset ++;
@ -154,6 +155,17 @@ static FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric (struct DecoderState *ds
default:
{
if (hasError)
{
if (intNeg == 1)
{
return SetError(ds, -1, "Value is too big!");
}
else if (intNeg == -1)
{
return SetError(ds, -1, overflowLimit == LLONG_MAX ? "Value is too big!" : "Value is too small");
}
}
goto BREAK_INT_LOOP;
break;
}

View File

@ -525,6 +525,7 @@ def test_decode_no_assert(test_input):
[
("31337", 31337),
("-31337", -31337),
("100000000000000000000.0", 1e20),
],
)
def test_decode(test_input, expected):