Merge pull request #22964 from ClickHouse/uniq-up-to-ubsan

Check out of range values in FieldVisitorConverToNumber
This commit is contained in:
Maksim Kita 2021-04-12 11:50:19 +03:00 committed by GitHub
commit b9fe85d537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 2 deletions

View File

@ -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<T>::max() || x < std::numeric_limits<T>::lowest())
{
throw Exception("Cannot convert out of range floating point value to integer type", ErrorCodes::CANNOT_CONVERT_TYPE);
}
}
if constexpr (std::is_same_v<Decimal256, T>)
{
return Int256(x);
}
else
{
return T(x);
}
}
T operator() (const UInt128 &) const

View File

@ -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));

View File

@ -0,0 +1,2 @@
SELECT uniqUpTo(1e100)(number) FROM numbers(5); -- { serverError 70 }
SELECT uniqUpTo(-1e100)(number) FROM numbers(5); -- { serverError 70 }