diff --git a/src/Functions/array/arraySlice.cpp b/src/Functions/array/arraySlice.cpp index 0044de0e93e..1e72e6a45cf 100644 --- a/src/Functions/array/arraySlice.cpp +++ b/src/Functions/array/arraySlice.cpp @@ -119,7 +119,7 @@ public: if (offset > 0) sink = GatherUtils::sliceFromLeftConstantOffsetUnbounded(*source, static_cast(offset - 1)); else - sink = GatherUtils::sliceFromRightConstantOffsetUnbounded(*source, static_cast(-offset)); + sink = GatherUtils::sliceFromRightConstantOffsetUnbounded(*source, -static_cast(offset)); } else if (isColumnConst(*length_column)) { @@ -127,7 +127,7 @@ public: if (offset > 0) sink = GatherUtils::sliceFromLeftConstantOffsetBounded(*source, static_cast(offset - 1), length); else - sink = GatherUtils::sliceFromRightConstantOffsetBounded(*source, static_cast(-offset), length); + sink = GatherUtils::sliceFromRightConstantOffsetBounded(*source, -static_cast(offset), length); } else sink = GatherUtils::sliceDynamicOffsetBounded(*source, *offset_column, *length_column); diff --git a/tests/queries/0_stateless/01664_array_slice_ubsan.reference b/tests/queries/0_stateless/01664_array_slice_ubsan.reference new file mode 100644 index 00000000000..abae410d95c --- /dev/null +++ b/tests/queries/0_stateless/01664_array_slice_ubsan.reference @@ -0,0 +1 @@ +[0,0,0] diff --git a/tests/queries/0_stateless/01664_array_slice_ubsan.sql b/tests/queries/0_stateless/01664_array_slice_ubsan.sql new file mode 100644 index 00000000000..604aa1c584b --- /dev/null +++ b/tests/queries/0_stateless/01664_array_slice_ubsan.sql @@ -0,0 +1 @@ +SELECT arraySlice(groupArray(x), -9223372036854775808, NULL) AS y FROM (SELECT '6553.5', uniqState(NULL) AS x FROM numbers(3) GROUP BY number); \ No newline at end of file