Skip to content
Open
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
7 changes: 7 additions & 0 deletions ext/json/ext/parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,13 @@ static inline VALUE json_decode_float(JSON_ParserConfig *config, uint64_t mantis
}

if (RB_UNLIKELY(mantissa_digits > 18 || mantissa_digits + exponent < -307)) {
// If the value is so small that it definitely underflows to 0.0, return early
// to avoid triggering a "Float out of range" warning from rb_cstr_to_dbl.
// When mantissa_digits + exponent < -324, value < 10^(-324) < DBL_TRUE_MIN/2,
// so it rounds to 0 in IEEE 754 round-to-nearest.
if (RB_UNLIKELY(mantissa_digits + exponent < -324)) {
return rb_float_new(negative ? -0.0 : 0.0);
}
return json_decode_large_float(start, end - start);
}

Expand Down
Loading