diff --git a/src/Functions/GatherUtils/Algorithms.h b/src/Functions/GatherUtils/Algorithms.h index 616257493eb..de0b1763afd 100644 --- a/src/Functions/GatherUtils/Algorithms.h +++ b/src/Functions/GatherUtils/Algorithms.h @@ -711,7 +711,7 @@ void resizeDynamicSize(ArraySource && array_source, ValueSource && value_source, } else { - auto length = static_cast(-size); + auto length = -static_cast(size); if (length > MAX_ARRAY_SIZE) throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Too large array size: {}, maximum: {}", length, MAX_ARRAY_SIZE); @@ -760,7 +760,7 @@ void resizeConstantSize(ArraySource && array_source, ValueSource && value_source } else { - auto length = static_cast(-size); + auto length = -static_cast(size); if (length > MAX_ARRAY_SIZE) throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, "Too large array size: {}, maximum: {}", length, MAX_ARRAY_SIZE); diff --git a/tests/queries/0_stateless/01682_gather_utils_ubsan.reference b/tests/queries/0_stateless/01682_gather_utils_ubsan.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01682_gather_utils_ubsan.sql b/tests/queries/0_stateless/01682_gather_utils_ubsan.sql new file mode 100644 index 00000000000..2388586e8fe --- /dev/null +++ b/tests/queries/0_stateless/01682_gather_utils_ubsan.sql @@ -0,0 +1 @@ +SELECT arrayResize([1, 2, 3], -9223372036854775808); -- { serverError 128 }