**Describe the bug**
https://clickhouse-test-reports.s3.yandex.net/19357/375db8ce7e2a042229fb0d0d26ff7c7a74c8d73c/fuzzer_ubsan/report.html#fail1

**How to reproduce**
Try to reproduce the report and copy the tables and queries involved.

**Error message and/or stacktrace**
``` sql
SELECT quantileExactWeighted((NULL, NULL, NULL, NULL))((NULL), number, (NULL, 0, 255), 9223372036854775807), quantilesExactWeighted(0, 1., 0.9998999834060669, 0.00009999999747378752, 0., 0., 0.9998999834060669, 0., 0.00009999999747378752, 0.5, 1., 0.9998999834060669, 0.00009999999747378752, 0., 1., 1)(number, 9223372036854775807) FROM (SELECT (NULL, NULL, NULL, 0.9998999834060669), number FROM system.numbers LIMIT 10)
```

```
../src/AggregateFunctions/QuantileExactWeighted.h:168:29: runtime error: 1.84467e+19 is outside the range of representable values of type 'unsigned long' Received signal -3 Received signal Unknown signal (-3)
```

```
2021.01.21 18:32:37.468417 [ 193 ] {} <Fatal> BaseDaemon: ########################################
2021.01.21 18:32:37.468529 [ 193 ] {} <Fatal> BaseDaemon: (version 21.2.1.5753, build id: A4DF22BE5C3F8AA289D121BC4F0371D35348003A) (from thread 177) (query_id: 75b08fe7-2287-49a4-8750-61e158bb684b) Received signal Unknown signal (-3)
2021.01.21 18:32:37.468571 [ 193 ] {} <Fatal> BaseDaemon: Sanitizer trap.
2021.01.21 18:32:37.468630 [ 193 ] {} <Fatal> BaseDaemon: Stack trace: 0xe03acf5 0xe264d16 0xdffed16 0xe00c7af 0xfc4770d 0xfc44d72 0x19e4d755 0x19d1289c 0x1af002c0 0x1aca2f09 0x1aca2df7 0x1aca1804 0x1aca00da 0x1ac9fb9b 0x1acb258c 0x1acb24e7 0x1acb23a2 0xe066dff 0xe06aac6 0x7f3db8ec7609 0x7f3db8dee293
2021.01.21 18:32:37.468773 [ 193 ] {} <Fatal> BaseDaemon: 0. ./obj-x86_64-linux-gnu/../src/Common/StackTrace.cpp:293: StackTrace::StackTrace() @ 0xe03acf5 in /workspace/clickhouse
2021.01.21 18:32:37.469090 [ 193 ] {} <Fatal> BaseDaemon: 1. ./obj-x86_64-linux-gnu/../base/daemon/BaseDaemon.cpp:380: sanitizerDeathCallback() @ 0xe264d16 in /workspace/clickhouse
2021.01.21 18:32:37.472744 [ 193 ] {} <Fatal> BaseDaemon: 2. __sanitizer::Die() @ 0xdffed16 in /workspace/clickhouse
2021.01.21 18:32:37.476512 [ 193 ] {} <Fatal> BaseDaemon: 3. ? @ 0xe00c7af in /workspace/clickhouse
2021.01.21 18:32:37.489674 [ 193 ] {} <Fatal> BaseDaemon: 4. ./obj-x86_64-linux-gnu/../src/AggregateFunctions/QuantileExactWeighted.h:176: DB::QuantileExactWeighted<unsigned long>::getMany(double const*, unsigned long const*, unsigned long, unsigned long*) const @ 0xfc4770d in /workspace/clickhouse
2021.01.21 18:32:37.502691 [ 193 ] {} <Fatal> BaseDaemon: 5. ./obj-x86_64-linux-gnu/../src/AggregateFunctions/AggregateFunctionQuantile.h:181: DB::AggregateFunctionQuantile<unsigned long, DB::QuantileExactWeighted<unsigned long>, DB::NameQuantilesExactWeighted, true, void, true>::insertResultInto(char*, DB::IColumn&, DB::Arena*) const @ 0xfc44d72 in /workspace/clickhouse
2021.01.21 18:32:37.510249 [ 193 ] {} <Fatal> BaseDaemon: 6. ./obj-x86_64-linux-gnu/../src/Interpreters/Aggregator.cpp:1084: void DB::Aggregator::insertAggregatesIntoColumns<char*>(char*&, std::__1::vector<COW<DB::IColumn>::mutable_ptr<DB::IColumn>, std::__1::allocator<COW<DB::IColumn>::mutable_ptr<DB::IColumn> > >&, DB::Arena*) const @ 0x19e4d755 in /workspace/clickhouse
2021.01.21 18:32:37.512350 [ 193 ] {} <Fatal> BaseDaemon: 7. ./obj-x86_64-linux-gnu/../src/Interpreters/Aggregator.cpp:1318: DB::Aggregator::prepareBlockAndFillWithoutKey(DB::AggregatedDataVariants&, bool, bool) const @ 0x19d1289c in /workspace/clickhouse
2021.01.21 18:32:37.515771 [ 193 ] {} <Fatal> BaseDaemon: 8. ./obj-x86_64-linux-gnu/../src/Processors/Transforms/AggregatingTransform.cpp:344: DB::ConvertingAggregatedToChunksTransform::initialize() @ 0x1af002c0 in /workspace/clickhouse
2021.01.21 18:32:37.518511 [ 193 ] {} <Fatal> BaseDaemon: 9. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:87: DB::executeJob(DB::IProcessor*) @ 0x1aca2f09 in /workspace/clickhouse
2021.01.21 18:32:37.521174 [ 193 ] {} <Fatal> BaseDaemon: 10. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:99: 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&) @ 0x1aca2df7 in /workspace/clickhouse
2021.01.21 18:32:37.523722 [ 193 ] {} <Fatal> BaseDaemon: 11. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:0: DB::PipelineExecutor::executeStepImpl(unsigned long, unsigned long, std::__1::atomic<bool>*) @ 0x1aca1804 in /workspace/clickhouse
2021.01.21 18:32:37.526316 [ 193 ] {} <Fatal> BaseDaemon: 12. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:0: DB::PipelineExecutor::executeImpl(unsigned long) @ 0x1aca00da in /workspace/clickhouse
2021.01.21 18:32:37.528848 [ 193 ] {} <Fatal> BaseDaemon: 13. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PipelineExecutor.cpp:398: DB::PipelineExecutor::execute(unsigned long) @ 0x1ac9fb9b in /workspace/clickhouse
2021.01.21 18:32:37.531484 [ 193 ] {} <Fatal> BaseDaemon: 14. ./obj-x86_64-linux-gnu/../src/Processors/Executors/PullingAsyncPipelineExecutor.cpp:74: DB::threadFunction(DB::PullingAsyncPipelineExecutor::Data&, std::__1::shared_ptr<DB::ThreadGroupStatus>, unsigned long) @ 0x1acb258c in /workspace/clickhouse
2021.01.21 18:32:37.534234 [ 193 ] {} <Fatal> BaseDaemon: 15. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/type_traits:3682: 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&) @ 0x1acb24e7 in /workspace/clickhouse
2021.01.21 18:32:37.536891 [ 193 ] {} <Fatal> BaseDaemon: 16. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/tuple:0: decltype(std::__1::forward<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(fp)()) std::__1::__invoke<ThreadFromGlobalPool::ThreadFromGlobalPool<DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&)::'lambda'()&>(DB::PullingAsyncPipelineExecutor::pull(DB::Chunk&, unsigned long)::$_0&&) @ 0x1acb23a2 in /workspace/clickhouse
2021.01.21 18:32:37.536980 [ 193 ] {} <Fatal> BaseDaemon: 17. ./obj-x86_64-linux-gnu/../contrib/libcxx/include/functional:2533: ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0xe066dff in /workspace/clickhouse
2021.01.21 18:32:37.537141 [ 193 ] {} <Fatal> BaseDaemon: 18. ./obj-x86_64-linux-gnu/../src/Common/ThreadPool.cpp:0: void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda1'()> >(void*) @ 0xe06aac6 in /workspace/clickhouse
2021.01.21 18:32:37.537180 [ 193 ] {} <Fatal> BaseDaemon: 19. start_thread @ 0x9609 in /usr/lib/x86_64-linux-gnu/libpthread-2.31.so
2021.01.21 18:32:37.537222 [ 193 ] {} <Fatal> BaseDaemon: 20. clone @ 0x122293 in /usr/lib/x86_64-linux-gnu/libc-2.31.so
2021.01.21 18:32:37.714278 [ 193 ] {} <Fatal> BaseDaemon: Calculated checksum of the binary: A707FD14046A876A5B5DC2826FBCE6D6. There is no information about the reference checksum.
```
{
        size_t size = map.size();
        if (0 == size)
        {
            for (size_t i = 0; i < num_levels; ++i)
                result[i] = Value();
            return;
        }
        
        using Pair = typename Map::value_type;
        std::unique_ptr<Pair[]> array_holder(new Pair[size]);
        Pair * array = array_holder.get();
        size_t i = 0;
        UInt64 sum_weight = 0;
        for (const auto & pair : map)
        {
            sum_weight += pair.getMapped();
            array[i] = pair.getValue();
            ++i;
        }
        std::sort(array, array + size, [](const Pair & a, const Pair & b) { return a.first < b.first; });
        UInt64 accumulated = 0;
        const Pair * it = array;
        const Pair * end = array + size;
        size_t level_index = 0;
        UInt64 threshold = std::ceil(sum_weight * levels[indices[level_index]]);
        while (it < end)