Skip to content

Commit

Permalink
Merge pull request #442 from dwhswenson/fix_large_floats
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Nov 16, 2020
2 parents 92671ea + cdcf5be commit 7cceea1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/ultrajsondec.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ++;
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_ujson.py
Expand Up @@ -525,6 +525,7 @@ def test_decode_no_assert(test_input):
[
("31337", 31337),
("-31337", -31337),
("100000000000000000000.0", 1e20),
],
)
def test_decode(test_input, expected):
Expand Down

0 comments on commit 7cceea1

Please sign in to comment.