diff --git a/src/Common/FieldVisitors.h b/src/Common/FieldVisitors.h index 954cd004e84..5adbf2b01ac 100644 --- a/src/Common/FieldVisitors.h +++ b/src/Common/FieldVisitors.h @@ -185,12 +185,20 @@ public: /// Conversion of infinite values to integer is undefined. throw Exception("Cannot convert infinite value to integer type", ErrorCodes::CANNOT_CONVERT_TYPE); } + else if (x > std::numeric_limits::max() || x < std::numeric_limits::lowest()) + { + throw Exception("Cannot convert out of range floating point value to integer type", ErrorCodes::CANNOT_CONVERT_TYPE); + } } if constexpr (std::is_same_v) + { return Int256(x); + } else + { return T(x); + } } T operator() (const UInt128 &) const diff --git a/tests/queries/0_stateless/01386_negative_float_constant_key_condition.reference b/tests/queries/0_stateless/01386_negative_float_constant_key_condition.reference index 44e0be8e356..bb0b1cf658d 100644 --- a/tests/queries/0_stateless/01386_negative_float_constant_key_condition.reference +++ b/tests/queries/0_stateless/01386_negative_float_constant_key_condition.reference @@ -1,4 +1,3 @@ 0 0 0 -0 diff --git a/tests/queries/0_stateless/01386_negative_float_constant_key_condition.sql b/tests/queries/0_stateless/01386_negative_float_constant_key_condition.sql index 216f43c4285..c2191d6ab96 100644 --- a/tests/queries/0_stateless/01386_negative_float_constant_key_condition.sql +++ b/tests/queries/0_stateless/01386_negative_float_constant_key_condition.sql @@ -12,7 +12,7 @@ SETTINGS index_granularity = 8192; INSERT INTO t0 VALUES (0, 0); SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND -1524532316)); -SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND -1.0)); +SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND -1.0)); -- { serverError 70 } SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND inf)); SELECT t0.c1 FROM t0 WHERE NOT (t0.c1 OR (t0.c0 AND nan)); diff --git a/tests/queries/0_stateless/01804_uniq_up_to_ubsan.reference b/tests/queries/0_stateless/01804_uniq_up_to_ubsan.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01804_uniq_up_to_ubsan.sql b/tests/queries/0_stateless/01804_uniq_up_to_ubsan.sql new file mode 100644 index 00000000000..fcbe585b70a --- /dev/null +++ b/tests/queries/0_stateless/01804_uniq_up_to_ubsan.sql @@ -0,0 +1,2 @@ +SELECT uniqUpTo(1e100)(number) FROM numbers(5); -- { serverError 70 } +SELECT uniqUpTo(-1e100)(number) FROM numbers(5); -- { serverError 70 }