https://s3.amazonaws.com/clickhouse-test-reports/0/1f9ea15aaba59b5ee4cac07eae1febeaf79ecd5b/stress_test__ubsan_.html

```
../src/Interpreters/SortedBlocksWriter.cpp:259:65: runtime error: member call on null pointer of type 'DB::TemporaryFileOnDisk'
    #0 0x25d5098c in DB::SortedBlocksWriter::streamFromFile(std::__1::unique_ptr<DB::TemporaryFileOnDisk, std::__1::default_delete<DB::TemporaryFileOnDisk> > const&) const build_docker/../src/Interpreters/SortedBlocksWriter.cpp:259:65
    #1 0x25d502d4 in DB::SortedBlocksWriter::premerge() build_docker/../src/Interpreters/SortedBlocksWriter.cpp:229:32
    #2 0x25d50a08 in DB::SortedBlocksWriter::finishMerge(std::__1::function<void (DB::Block const&)>) build_docker/../src/Interpreters/SortedBlocksWriter.cpp:237:28
    #3 0x25b82978 in DB::MergeJoin::mergeFlushedRightBlocks() build_docker/../src/Interpreters/MergeJoin.cpp:625:41
    #4 0x25b81915 in DB::MergeJoin::setTotals(DB::Block const&) build_docker/../src/Interpreters/MergeJoin.cpp:567:5
    #5 0x2751923a in DB::FillingRightJoinSideTransform::work() build_docker/../src/Processors/Transforms/JoiningTransform.cpp:294:15
    #6 0x27139224 in DB::executeJob(DB::ExecutingGraph::Node*, DB::ReadProgressCallback*) build_docker/../src/Processors/Executors/ExecutionThreadContext.cpp:47:26
    #7 0x27138d8b in DB::ExecutionThreadContext::executeTask() build_docker/../src/Processors/Executors/ExecutionThreadContext.cpp:92:9
    #8 0x27128e3a in DB::PipelineExecutor::executeStepImpl(unsigned long, std::__1::atomic<bool>*) build_docker/../src/Processors/Executors/PipelineExecutor.cpp:228:26
    #9 0x271288f7 in DB::PipelineExecutor::executeStep(std::__1::atomic<bool>*) build_docker/../src/Processors/Executors/PipelineExecutor.cpp:125:5
    #10 0x2713fb7d in DB::PullingPipelineExecutor::pull(DB::Chunk&) build_docker/../src/Processors/Executors/PullingPipelineExecutor.cpp:54:20
    #11 0x27610ea9 in DB::ExecutingInnerQueryFromViewTransform::onGenerate() build_docker/../src/Processors/Transforms/buildPushingToViewsChain.cpp:575:40
    #12 0x2750ae33 in DB::ExceptionKeepingTransform::work()::$_2::operator()() const build_docker/../src/Processors/Transforms/ExceptionKeepingTransform.cpp:165:63
    #13 0x2750ae33 in decltype(static_cast<DB::ExceptionKeepingTransform::work()::$_2&>(fp)()) std::__1::__invoke<DB::ExceptionKeepingTransform::work()::$_2&>(DB::ExceptionKeepingTransform::work()::$_2&) build_docker/../contrib/libcxx/include/type_traits:3640:23
    #14 0x2750a8f1 in std::__1::__function::__policy_func<void ()>::operator()() const build_docker/../contrib/libcxx/include/__functional/function.h:843:16
    #15 0x2750a8f1 in std::__1::function<void ()>::operator()() const build_docker/../contrib/libcxx/include/__functional/function.h:1184:12
    #16 0x2750a8f1 in DB::runStep(std::__1::function<void ()>, DB::ThreadStatus*, std::__1::atomic<unsigned long>*) build_docker/../src/Processors/Transforms/ExceptionKeepingTransform.cpp:115:9
    #17 0x27509db0 in DB::ExceptionKeepingTransform::work() build_docker/../src/Processors/Transforms/ExceptionKeepingTransform.cpp:165:34
    #18 0x27139224 in DB::executeJob(DB::ExecutingGraph::Node*, DB::ReadProgressCallback*) build_docker/../src/Processors/Executors/ExecutionThreadContext.cpp:47:26
    #19 0x27138d8b in DB::ExecutionThreadContext::executeTask() build_docker/../src/Processors/Executors/ExecutionThreadContext.cpp:92:9
    #20 0x27128e3a in DB::PipelineExecutor::executeStepImpl(unsigned long, std::__1::atomic<bool>*) build_docker/../src/Processors/Executors/PipelineExecutor.cpp:228:26
    #21 0x27128674 in DB::PipelineExecutor::executeSingleThread(unsigned long) build_docker/../src/Processors/Executors/PipelineExecutor.cpp:194:5
    #22 0x27128674 in DB::PipelineExecutor::executeImpl(unsigned long) build_docker/../src/Processors/Executors/PipelineExecutor.cpp:367:9
    #23 0x27128429 in DB::PipelineExecutor::execute(unsigned long) build_docker/../src/Processors/Executors/PipelineExecutor.cpp:89:9
    #24 0x271278f6 in DB::threadFunction(DB::CompletedPipelineExecutor::Data&, std::__1::shared_ptr<DB::ThreadGroupStatus>, unsigned long) build_docker/../src/Processors/Executors/CompletedPipelineExecutor.cpp:43:24
    #25 0x271277ba in DB::CompletedPipelineExecutor::execute()::$_0::operator()() const build_docker/../src/Processors/Executors/CompletedPipelineExecutor.cpp:79:13
    #26 0x271277ba in decltype(static_cast<DB::CompletedPipelineExecutor::execute()::$_0&>(fp)()) std::__1::__invoke_constexpr<DB::CompletedPipelineExecutor::execute()::$_0&>(DB::CompletedPipelineExecutor::execute()::$_0&) build_docker/../contrib/libcxx/include/type_traits:3648:23
    #27 0x271277ba in decltype(auto) std::__1::__apply_tuple_impl<DB::CompletedPipelineExecutor::execute()::$_0&, std::__1::tuple<>&>(DB::CompletedPipelineExecutor::execute()::$_0&, std::__1::tuple<>&, std::__1::__tuple_indices<>) build_docker/../contrib/libcxx/include/tuple:1595:1
    #28 0x271277ba in decltype(auto) std::__1::apply<DB::CompletedPipelineExecutor::execute()::$_0&, std::__1::tuple<>&>(DB::CompletedPipelineExecutor::execute()::$_0&, std::__1::tuple<>&) build_docker/../contrib/libcxx/include/tuple:1604:1
    #29 0x271277ba in ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::CompletedPipelineExecutor::execute()::$_0>(DB::CompletedPipelineExecutor::execute()::$_0&&)::'lambda'()::operator()() build_docker/../src/Common/ThreadPool.h:193:13
    #30 0x271277ba in decltype(static_cast<DB::CompletedPipelineExecutor::execute()::$_0>(fp)()) std::__1::__invoke<ThreadFromGlobalPoolImpl<true>::ThreadFromGlobalPoolImpl<DB::CompletedPipelineExecutor::execute()::$_0>(DB::CompletedPipelineExecutor::execute()::$_0&&)::'lambda'()&>(DB::CompletedPipelineExecutor::execute()::$_0&&) build_docker/../contrib/libcxx/include/type_traits:3640:23
    #31 0x103f9ad2 in std::__1::__function::__policy_func<void ()>::operator()() const build_docker/../contrib/libcxx/include/__functional/function.h:843:16
    #32 0x103f9ad2 in std::__1::function<void ()>::operator()() const build_docker/../contrib/libcxx/include/__functional/function.h:1184:12
    #33 0x103f9ad2 in ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) build_docker/../src/Common/ThreadPool.cpp:294:17
    #34 0x103fda22 in void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>, bool)::'lambda0'()::operator()() const build_docker/../src/Common/ThreadPool.cpp:144:73
    #35 0x103fda22 in decltype(static_cast<void>(fp)()) std::__1::__invoke<void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>, bool)::'lambda0'()>(void&&) build_docker/../contrib/libcxx/include/type_traits:3640:23
    #36 0x103fda22 in void std::__1::__thread_execute<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>, bool)::'lambda0'()>(std::__1::tuple<void, void ThreadPoolImpl<std::__1::thread>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>, bool)::'lambda0'()>&, std::__1::__tuple_indices<>) build_docker/../contrib/libcxx/include/thread:282:5
    #37 0x103fda22 in 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>, bool)::'lambda0'()> >(void*) build_docker/../contrib/libcxx/include/thread:293:5
    #38 0x7f18ec4b0608 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8608) (BuildId: 7b4536f41cdaa5888408e82d0836e33dcf436466)
    #39 0x7f18ec3d5132 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x11f132) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../src/Interpreters/SortedBlocksWriter.cpp:259:65 in 
```
{
    auto tmp_file = std::make_unique<TemporaryFileOnDisk>(disk, CurrentMetrics::TemporaryFilesForJoin);
    auto write_stat = TemporaryFileStream::write(tmp_file->getPath(), header, std::move(pipeline), codec);
    ProfileEvents::increment(ProfileEvents::ExternalProcessingCompressedBytesTotal, write_stat.compressed_bytes);
    ProfileEvents::increment(ProfileEvents::ExternalProcessingUncompressedBytesTotal, write_stat.uncompressed_bytes);
    ProfileEvents::increment(ProfileEvents::ExternalJoinCompressedBytes, write_stat.compressed_bytes);
    ProfileEvents::increment(ProfileEvents::ExternalJoinUncompressedBytes, write_stat.uncompressed_bytes);
    ProfileEvents::increment(ProfileEvents::ExternalJoinWritePart);
    return tmp_file;
}
SortedBlocksWriter::SortedFiles flushToManyFiles(const DiskPtr & disk, const Block & header, QueryPipelineBuilder builder,