Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,11 @@ static inline VALUE json_parse_number(JSON_ParserState *state, JSON_ParserConfig
raise_parse_error_at("invalid number: %s", state, start);
}

exponent = negative_exponent ? -abs_exponent : abs_exponent;
if (RB_UNLIKELY(exponent_digits >= 20 || abs_exponent > (uint64_t)INT64_MAX)) {
exponent = negative_exponent ? INT64_MIN : INT64_MAX;
} else {
exponent = negative_exponent ? -(int64_t)abs_exponent : (int64_t)abs_exponent;
}
}

if (integer) {
Expand Down
8 changes: 8 additions & 0 deletions test/json/json_ryu_fallback_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,13 @@ def test_large_exponent_numbers
assert_equal(-0.0, JSON.parse("-99999999999999999e-4294967296"))
assert_equal(-Float::INFINITY, JSON.parse("-1e4294967295"))
assert_equal(-Float::INFINITY, JSON.parse("-1e4294967297"))

assert_equal(Float::INFINITY, JSON.parse("1e9223372036854775808"))
assert_equal(Float::INFINITY, JSON.parse("1e9999999999999999999"))
assert_equal(Float::INFINITY, JSON.parse("1e18446744073709551616"))
assert_equal(Float::INFINITY, JSON.parse("1e10000000000000000000"))
assert_equal(Float::INFINITY, JSON.parse("1e184467440737095516160"))
assert_equal 0.0, JSON.parse("1e-18446744073709551615")
assert_equal 0.0, JSON.parse("1e-9223372036854775809")
end
end
Loading