From 90e0de78e5e0446528cab569081a6e364426b48f Mon Sep 17 00:00:00 2001 From: walter Date: Wed, 20 Mar 2024 08:54:42 +0800 Subject: [PATCH] [fix](snapshot-loader) Fix be crash caused by deref end() iterator (#32489) 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 c4dcc7f34def2c..da22a7c9167ef3 100644 --- a/be/src/runtime/snapshot_loader.cpp +++ b/be/src/runtime/snapshot_loader.cpp @@ -316,7 +316,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