```
SELECT * FROM numbers(4) GROUP BY number WITH TOTALS HAVING sum(number) <= arrayJoin([])



clickhouse-server: /home/akuzm/ch2/ch/src/Common/PODArray.h:376: const T &DB::PODArray<char8_t, 4096, Allocator<false, false>, 15, 16>::operator[](ssize_t) const [T = char8_t, initial_bytes = 4096, TAllocator = Allocator<false, false>, pad_right_ = 15, pad_left_ = 16]: Assertion `(n >= (static_cast<ssize_t>(pad_left_) ? -1 : 0)) && (n <= static_cast<ssize_t>(this->size()))' failed.
2020.10.16 16:07:18.347404 [ 1287685 ] {} <Trace> BaseDaemon: Received signal 6
2020.10.16 16:07:18.347777 [ 1287751 ] {} <Fatal> BaseDaemon: ########################################
2020.10.16 16:07:18.348202 [ 1287751 ] {} <Fatal> BaseDaemon: (version 20.11.1.1, build id: 575093CBC993DB2F) (from thread 1287723) (query_id: d0b188c0-6150-4045-9337-b84fb0c5a3e7) Received signal Aborted (6)
2020.10.16 16:07:18.348367 [ 1287751 ] {} <Fatal> BaseDaemon: 
2020.10.16 16:07:18.348552 [ 1287751 ] {} <Fatal> BaseDaemon: Stack trace: 0x7f833872f18b 0x7f833870e859 0x7f833870e729 0x7f833871ff36 0x7f833646352d 0x7f83228da02a 0x7f83228d9c0c 0x7f83256c51e5 0x7f8323381be8 0x7f83228d926b 0x7f83231b5cfc 0x7f83231b5c5f 0x7f83231b5c1d 0x7f83231b5bcd 0x7f83231b5b9d 0x7f83231b4cee 0x7f833ce6fdb5 0x7f833ce6fd55 0x7f83231b3605 0x7f83231b3df9 0x7f83231b2340 0x7f83231b1916 0x7f83231d4afd 0x7f83231d4a62 0x7f83231d49ed 0x7f83231d49b1 0x7f83231d48f2 0x7f83231d4802
2020.10.16 16:07:18.348908 [ 1287751 ] {} <Fatal> BaseDaemon: 4. /build/glibc-YYA7BZ/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51: gsignal @ 0x4618b in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
2020.10.16 16:07:18.349130 [ 1287751 ] {} <Fatal> BaseDaemon: 5. /build/glibc-YYA7BZ/glibc-2.31/stdlib/abort.c:81: abort @ 0x25859 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
2020.10.16 16:07:18.349380 [ 1287751 ] {} <Fatal> BaseDaemon: 6. /build/glibc-YYA7BZ/glibc-2.31/intl/loadmsgcat.c:509: _nl_load_domain.cold @ 0x25729 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
2020.10.16 16:07:18.349681 [ 1287751 ] {} <Fatal> BaseDaemon: 7. ? @ 0x36f36 in /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.31.so
2020.10.16 16:07:18.351185 [ 1287751 ] {} <Fatal> BaseDaemon: 8. /home/akuzm/ch2/ch/src/Common/PODArray.h:0: DB::PODArray<char8_t, 4096ul, Allocator<false, false>, 15ul, 16ul>::operator[](long) const @ 0x3b6852d in /home/akuzm/ch2/build-clang10/src/AggregateFunctions/libclickhouse_aggregate_functionsd.so
2020.10.16 16:07:18.351965 [ 1287751 ] {} <Fatal> BaseDaemon: 9. /home/akuzm/ch2/ch/src/Processors/Transforms/TotalsHavingTransform.cpp:228: DB::TotalsHavingTransform::addToTotals(DB::Chunk const&, DB::PODArray<char8_t, 4096ul, Allocator<false, false>, 15ul, 16ul> const*) @ 0x2cf02a in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_transformsd.so
2020.10.16 16:07:18.352761 [ 1287751 ] {} <Fatal> BaseDaemon: 10. /home/akuzm/ch2/ch/src/Processors/Transforms/TotalsHavingTransform.cpp:188: DB::TotalsHavingTransform::transform(DB::Chunk&) @ 0x2cec0c in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_transformsd.so
2020.10.16 16:07:18.356715 [ 1287751 ] {} <Fatal> BaseDaemon: 11. /home/akuzm/ch2/ch/src/Processors/ISimpleTransform.h:43: DB::ISimpleTransform::transform(DB::Chunk&, DB::Chunk&) @ 0xb611e5 in /home/akuzm/ch2/build-clang10/src/libclickhouse_storagesd.so
2020.10.16 16:07:18.357141 [ 1287751 ] {} <Fatal> BaseDaemon: 12. /home/akuzm/ch2/ch/src/Processors/ISimpleTransform.cpp:89: DB::ISimpleTransform::work() @ 0x19abe8 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processorsd.so
2020.10.16 16:07:18.357821 [ 1287751 ] {} <Fatal> BaseDaemon: 13. /home/akuzm/ch2/ch/src/Processors/Transforms/TotalsHavingTransform.cpp:118: DB::TotalsHavingTransform::work() @ 0x2ce26b in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_transformsd.so
2020.10.16 16:07:18.358209 [ 1287751 ] {} <Fatal> BaseDaemon: 14. /home/akuzm/ch2/ch/src/Processors/Executors/PipelineExecutor.cpp:78: DB::executeJob(DB::IProcessor*) @ 0x134cfc in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.358560 [ 1287751 ] {} <Fatal> BaseDaemon: 15. /home/akuzm/ch2/ch/src/Processors/Executors/PipelineExecutor.cpp:95: DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0::operator()() const @ 0x134c5f in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.358943 [ 1287751 ] {} <Fatal> BaseDaemon: 16. /home/akuzm/ch2/ch/contrib/libcxx/include/type_traits:3519: decltype(std::__1::forward<DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0&>(fp)()) std::__1::__invoke<DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0&>(DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0&) @ 0x134c1d in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.359341 [ 1287751 ] {} <Fatal> BaseDaemon: 17. /home/akuzm/ch2/ch/contrib/libcxx/include/__functional_base:349: void std::__1::__invoke_void_return_wrapper<void>::__call<DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0&>(DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0&) @ 0x134bcd in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.359679 [ 1287751 ] {} <Fatal> BaseDaemon: 18. /home/akuzm/ch2/ch/contrib/libcxx/include/functional:1540: std::__1::__function::__alloc_func<DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0, std::__1::allocator<DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0>, void ()>::operator()() @ 0x134b9d in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.359982 [ 1287751 ] {} <Fatal> BaseDaemon: 19. /home/akuzm/ch2/ch/contrib/libcxx/include/functional:1714: std::__1::__function::__func<DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0, std::__1::allocator<DB::PipelineExecutor::addJob(DB::ExecutingGraph::Node*)::$_0>, void ()>::operator()() @ 0x133cee in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.361326 [ 1287751 ] {} <Fatal> BaseDaemon: 20. /home/akuzm/ch2/ch/contrib/libcxx/include/functional:1867: std::__1::__function::__value_func<void ()>::operator()() const @ 0x178db5 in /home/akuzm/ch2/build-clang10/programs/server/libclickhouse-server-libd.so
2020.10.16 16:07:18.362598 [ 1287751 ] {} <Fatal> BaseDaemon: 21. /home/akuzm/ch2/ch/contrib/libcxx/include/functional:2473: std::__1::function<void ()>::operator()() const @ 0x178d55 in /home/akuzm/ch2/build-clang10/programs/server/libclickhouse-server-libd.so
2020.10.16 16:07:18.362901 [ 1287751 ] {} <Fatal> BaseDaemon: 22. /home/akuzm/ch2/ch/src/Processors/Executors/PipelineExecutor.cpp:564: DB::PipelineExecutor::executeStepImpl(unsigned long, unsigned long, std::__1::atomic<bool>*) @ 0x132605 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.363170 [ 1287751 ] {} <Fatal> BaseDaemon: 23. /home/akuzm/ch2/ch/src/Processors/Executors/PipelineExecutor.cpp:477: DB::PipelineExecutor::executeSingleThread(unsigned long, unsigned long) @ 0x132df9 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.363403 [ 1287751 ] {} <Fatal> BaseDaemon: 24. /home/akuzm/ch2/ch/src/Processors/Executors/PipelineExecutor.cpp:752: DB::PipelineExecutor::executeImpl(unsigned long) @ 0x131340 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.363620 [ 1287751 ] {} <Fatal> BaseDaemon: 25. /home/akuzm/ch2/ch/src/Processors/Executors/PipelineExecutor.cpp:399: DB::PipelineExecutor::execute(unsigned long) @ 0x130916 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.363898 [ 1287751 ] {} <Fatal> BaseDaemon: 26. /home/akuzm/ch2/ch/src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:79: DB::threadFunction(DB::PullingAsyncPipelineExecutor::Data&, std::__1::shared_ptr<DB::ThreadGroupStatus>, unsigned long) @ 0x153afd in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.364172 [ 1287751 ] {} <Fatal> BaseDaemon: 27. /home/akuzm/ch2/ch/src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:101: DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0::operator()() const @ 0x153a62 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.364444 [ 1287751 ] {} <Fatal> BaseDaemon: 28. /home/akuzm/ch2/ch/contrib/libcxx/include/type_traits:3525: decltype(std::__1::forward<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&>(fp)()) std::__1::__invoke_constexpr<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&) @ 0x1539ed in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.364736 [ 1287751 ] {} <Fatal> BaseDaemon: 29. /home/akuzm/ch2/ch/contrib/libcxx/include/tuple:1415: decltype(auto) std::__1::__apply_tuple_impl<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&, std::__1::tuple<>&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&, std::__1::tuple<>&, std::__1::__tuple_indices<>) @ 0x1539b1 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.365007 [ 1287751 ] {} <Fatal> BaseDaemon: 30. /home/akuzm/ch2/ch/contrib/libcxx/include/tuple:1424: decltype(auto) std::__1::apply<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&, std::__1::tuple<>&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&, std::__1::tuple<>&) @ 0x1538f2 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
2020.10.16 16:07:18.365271 [ 1287751 ] {} <Fatal> BaseDaemon: 31. /home/akuzm/ch2/ch/src/Common/ThreadPool.h:177: ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::'lambda'()::operator()() @ 0x153802 in /home/akuzm/ch2/build-clang10/src/libclickhouse_processors_executorsd.so
```
#include <Processors/Transforms/TotalsHavingTransform.h>
#include <Processors/Transforms/AggregatingTransform.h>
#include <Columns/ColumnAggregateFunction.h>
#include <Columns/FilterDescription.h>
#include <Common/typeid_cast.h>
#include <DataStreams/finalizeBlock.h>
#include <Interpreters/ExpressionActions.h>
namespace DB
{
namespace ErrorCodes
{
    extern const int LOGICAL_ERROR;
}
void finalizeChunk(Chunk & chunk)