diff --git a/src/Common/FieldVisitors.h b/src/Common/FieldVisitors.h index 954cd004e84..8be24a1be69 100644 --- a/src/Common/FieldVisitors.h +++ b/src/Common/FieldVisitors.h @@ -188,9 +188,16 @@ public: } if constexpr (std::is_same_v) + { return Int256(x); + } 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); + return T(x); + } } T operator() (const UInt128 &) const 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 }