From 1f2226b9db9731f5ebfadd532149c16af6ec6c09 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sat, 10 Apr 2021 23:38:14 +0300 Subject: [PATCH] Check out of range values in FieldVisitorConverToNumber --- src/Common/FieldVisitors.h | 7 +++++++ tests/queries/0_stateless/01804_uniq_up_to_ubsan.reference | 0 tests/queries/0_stateless/01804_uniq_up_to_ubsan.sql | 2 ++ 3 files changed, 9 insertions(+) create mode 100644 tests/queries/0_stateless/01804_uniq_up_to_ubsan.reference create mode 100644 tests/queries/0_stateless/01804_uniq_up_to_ubsan.sql 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 }