From 248540e58f2a1b5a71cc9bd955a8f94969b50c94 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Sun, 31 Jan 2021 10:10:37 +0300 Subject: [PATCH] Fix UBSan report in GatherUtils --- src/Functions/GatherUtils/Algorithms.h | 4 ++-- tests/queries/0_stateless/01682_gather_utils_ubsan.reference | 0 tests/queries/0_stateless/01682_gather_utils_ubsan.sql | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/01682_gather_utils_ubsan.reference create mode 100644 tests/queries/0_stateless/01682_gather_utils_ubsan.sql 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 }