From 268b15f221f97708a532858a3cf4d949fdee305c Mon Sep 17 00:00:00 2001 From: fenglv Date: Sat, 21 Nov 2020 12:59:40 +0000 Subject: [PATCH] fix toUInt256 stack overflow --- src/Functions/FunctionsConversion.h | 3 +++ .../01581_to_int256_uint256_inf_nan.reference | 6 ++++++ .../0_stateless/01581_to_int256_uint256_inf_nan.sql | 10 ++++++++++ 3 files changed, 19 insertions(+) create mode 100644 tests/queries/0_stateless/01581_to_int256_uint256_inf_nan.reference create mode 100644 tests/queries/0_stateless/01581_to_int256_uint256_inf_nan.sql diff --git a/src/Functions/FunctionsConversion.h b/src/Functions/FunctionsConversion.h index 70e8904cfc1..0bf4f3f506c 100644 --- a/src/Functions/FunctionsConversion.h +++ b/src/Functions/FunctionsConversion.h @@ -153,6 +153,9 @@ struct ConvertImpl { if constexpr (std::is_same_v || std::is_same_v) throw Exception("Unexpected UInt128 to big int conversion", ErrorCodes::NOT_IMPLEMENTED); + /// If From Data is Nan or Inf, throw exception + else if (!isFinite(vec_from[i])) + throw Exception("Unexpected inf or nan to big int conversion", ErrorCodes::NOT_IMPLEMENTED); else vec_to[i] = bigint_cast(vec_from[i]); } diff --git a/tests/queries/0_stateless/01581_to_int256_uint256_inf_nan.reference b/tests/queries/0_stateless/01581_to_int256_uint256_inf_nan.reference new file mode 100644 index 00000000000..37883cc6c47 --- /dev/null +++ b/tests/queries/0_stateless/01581_to_int256_uint256_inf_nan.reference @@ -0,0 +1,6 @@ +-9223372036854775808 +170141183460469231731687303715884105727 +-9223372036854775808 +170141183460469231731687303715884105727 +0 +0 diff --git a/tests/queries/0_stateless/01581_to_int256_uint256_inf_nan.sql b/tests/queries/0_stateless/01581_to_int256_uint256_inf_nan.sql new file mode 100644 index 00000000000..b28fc80774f --- /dev/null +++ b/tests/queries/0_stateless/01581_to_int256_uint256_inf_nan.sql @@ -0,0 +1,10 @@ +SELECT toInt64(inf); +SELECT toInt128(inf); +SELECT toInt256(inf); -- { serverError 48 } +SELECT toInt64(nan); +SELECT toInt128(nan); +SELECT toInt256(nan); -- { serverError 48 } +SELECT toUInt64(inf); +SELECT toUInt256(inf); -- { serverError 48 } +SELECT toUInt64(nan); +SELECT toUInt256(nan); -- { serverError 48 }