Skip to content

Commit 1072482

Browse files
committed
Fix parsing of *negative* out of bound floats.
1 parent 20454ba commit 1072482

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

ext/json/ext/parser/parser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,11 +864,11 @@ static inline VALUE json_decode_float(JSON_ParserConfig *config, uint64_t mantis
864864
}
865865

866866
if (RB_UNLIKELY(exponent > INT32_MAX)) {
867-
return CInfinity;
867+
return negative ? CMinusInfinity : CInfinity;
868868
}
869869

870870
if (RB_UNLIKELY(exponent < INT32_MIN)) {
871-
return rb_float_new(0.0);
871+
return rb_float_new(negative ? -0.0 : 0.0);
872872
}
873873

874874
// Fall back to rb_cstr_to_dbl for potential subnormals (rare edge case)

test/json/json_ryu_fallback_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,11 @@ def test_large_exponent_numbers
173173
assert_equal 0.0, JSON.parse("99999999999999999e-4294967296")
174174
assert_equal Float::INFINITY, JSON.parse("1e4294967295")
175175
assert_equal Float::INFINITY, JSON.parse("1e4294967297")
176+
177+
assert_equal -Float::INFINITY, JSON.parse("-1e4294967296")
178+
assert_equal -0.0, JSON.parse("-1e-4294967296")
179+
assert_equal -0.0, JSON.parse("-99999999999999999e-4294967296")
180+
assert_equal -Float::INFINITY, JSON.parse("-1e4294967295")
181+
assert_equal -Float::INFINITY, JSON.parse("-1e4294967297")
176182
end
177183
end

0 commit comments

Comments
 (0)