mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 08:40:50 +00:00
Merge pull request #16677 from ClickHouse/field-infinite-convert-to-int
Fix UBSan report when trying to convert infinite floating point number to integer
This commit is contained in:
commit
6d5e852356
@ -3,6 +3,7 @@
|
||||
#include <Core/DecimalFunctions.h>
|
||||
#include <Core/Field.h>
|
||||
#include <common/demangle.h>
|
||||
#include <Common/NaNUtils.h>
|
||||
|
||||
|
||||
class SipHash;
|
||||
@ -142,6 +143,19 @@ public:
|
||||
|
||||
T operator() (const Float64 & x) const
|
||||
{
|
||||
if constexpr (!std::is_floating_point_v<T>)
|
||||
{
|
||||
if (!isFinite(x))
|
||||
{
|
||||
/// When converting to bool it's ok (non-zero converts to true, NaN including).
|
||||
if (std::is_same_v<T, bool>)
|
||||
return true;
|
||||
|
||||
/// Conversion of infinite values to integer is undefined.
|
||||
throw Exception("Cannot convert infinite value to integer type", ErrorCodes::CANNOT_CONVERT_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<Decimal256, T>)
|
||||
return Int256(x);
|
||||
else
|
||||
|
@ -0,0 +1 @@
|
||||
SET max_threads = nan; -- { serverError 70 }
|
Loading…
Reference in New Issue
Block a user