Fix UBJSON high-precision floating-point overflow handling (#5323)

This adds a std::isfinite check to the UBJSON floating-point parsing path, throwing out_of_range.406 on overflow. This makes the UBJSON parser's behavior consistent with the normal JSON parser. Fixes #5322.

Signed-off-by: AJ369ninja <abhishek.j@iitg.ac.in>
Co-authored-by: AJ369ninja <abhishek.j@iitg.ac.in>
This commit is contained in:
hum4nBeing
2026-07-31 18:04:13 +02:00
committed by GitHub
co-authored by AJ369ninja
parent fd72ecfc8c
commit bc48951128
4 changed files with 26 additions and 2 deletions
+11 -1
View File
@@ -13374,7 +13374,17 @@ class binary_reader
case token_type::value_unsigned:
return sax->number_unsigned(number_lexer.get_number_unsigned());
case token_type::value_float:
return sax->number_float(number_lexer.get_number_float(), std::move(number_string));
{
const auto parsed_float = number_lexer.get_number_float();
if (JSON_HEDLEY_UNLIKELY(!std::isfinite(parsed_float)))
{
return sax->parse_error(
chars_read,
number_string,
out_of_range::create(406, concat("number overflow parsing '", number_string, '\''), nullptr));
}
return sax->number_float(parsed_float, std::move(number_string));
}
case token_type::uninitialized:
case token_type::literal_true:
case token_type::literal_false: