From 93aa52100fcdaf3de2cfa568a3eb12ae00cfef82 Mon Sep 17 00:00:00 2001 From: w41ter Date: Tue, 19 Mar 2024 11:56:13 +0000 Subject: [PATCH] [fix](snapshot-loader) Fix be crash caused by deref end() iterator The standard said that the input parameter `pos` of std::vector::erase must be valid and dereferenceable, the `end()` iterator cannot be used as a value of `pos`. I did some tests and the crash only occurs when the vector is empty. Fortunately `local_files` is usually not empty. --- be/src/runtime/snapshot_loader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/be/src/runtime/snapshot_loader.cpp b/be/src/runtime/snapshot_loader.cpp index 55b7d35f42e440..8032084378b9cb 100644 --- a/be/src/runtime/snapshot_loader.cpp +++ b/be/src/runtime/snapshot_loader.cpp @@ -338,7 +338,9 @@ Status SnapshotLoader::download(const std::map& src_to } // remove file which will be downloaded now. // this file will be added to local_files if it be downloaded successfully. - local_files.erase(find); + if (find != local_files.end()) { + local_files.erase(find); + } RETURN_IF_ERROR(_remote_fs->download(full_remote_file, full_local_file)); // 3. check md5 of the downloaded file