mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Merge pull request #5645 from coraxster/decimal-overflow-2
Fix float to decimal convert overflow, extreme values
This commit is contained in:
commit
41302c9910
@ -332,12 +332,12 @@ convertToDecimal(const typename FromDataType::FieldType & value, UInt32 scale)
|
||||
{
|
||||
static constexpr __int128 min_int128 = __int128(0x8000000000000000ll) << 64;
|
||||
static constexpr __int128 max_int128 = (__int128(0x7fffffffffffffffll) << 64) + 0xffffffffffffffffll;
|
||||
if (out < min_int128 || out > max_int128)
|
||||
if (out <= static_cast<ToNativeType>(min_int128) || out >= static_cast<ToNativeType>(max_int128))
|
||||
throw Exception("Decimal convert overflow. Float is out of Decimal range", ErrorCodes::DECIMAL_OVERFLOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (out < std::numeric_limits<ToNativeType>::min() || out > std::numeric_limits<ToNativeType>::max())
|
||||
if (out <= std::numeric_limits<ToNativeType>::min() || out >= std::numeric_limits<ToNativeType>::max())
|
||||
throw Exception("Decimal convert overflow. Float is out of Decimal range", ErrorCodes::DECIMAL_OVERFLOW);
|
||||
}
|
||||
return out;
|
||||
|
@ -258,3 +258,11 @@ select toDecimal128(1000000000000000000000.1, 18); -- { serverError 407 }
|
||||
select toDecimal32(-10000.1, 6); -- { serverError 407 }
|
||||
select toDecimal64(-10000.1, 18); -- { serverError 407 }
|
||||
select toDecimal128(-1000000000000000000000.1, 18); -- { serverError 407 }
|
||||
|
||||
select toDecimal32(2147483647.0 + 1.0, 0); -- { serverError 407 }
|
||||
select toDecimal64(9223372036854775807.0, 0); -- { serverError 407 }
|
||||
select toDecimal128(170141183460469231731687303715884105729.0, 0); -- { serverError 407 }
|
||||
|
||||
select toDecimal32(-2147483647.0 - 1.0, 0); -- { serverError 407 }
|
||||
select toDecimal64(-9223372036854775807.0, 0); -- { serverError 407 }
|
||||
select toDecimal128(-170141183460469231731687303715884105729.0, 0); -- { serverError 407 }
|
||||
|
Loading…
Reference in New Issue
Block a user