Skip to content

Commit 962a2e6

Browse files
authored
[Fix](inverted index) fix use after free when duplicate key in index dir when index file writer open index #42207 (#42300)
cherry pick from #42207
1 parent 9ffbc3d commit 962a2e6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

be/src/olap/rowset/segment_v2/inverted_index_file_writer.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,26 @@ Result<DorisFSDirectory*> InvertedIndexFileWriter::open(const TabletIndex* index
5151

5252
if (exists) {
5353
LOG(ERROR) << "try to init a directory:" << local_fs_index_path << " already exists";
54-
return ResultError(Status::InternalError("init_fulltext_index directory already exists"));
54+
return ResultError(
55+
Status::InternalError("InvertedIndexFileWriter::open directory already exists"));
5556
}
5657

5758
bool can_use_ram_dir = true;
5859
auto* dir = DorisFSDirectoryFactory::getDirectory(local_fs, local_fs_index_path.c_str(),
5960
can_use_ram_dir);
60-
_indices_dirs.emplace(std::make_pair(index_meta->index_id(), index_meta->get_index_suffix()),
61-
std::unique_ptr<DorisFSDirectory>(dir));
61+
auto key = std::make_pair(index_meta->index_id(), index_meta->get_index_suffix());
62+
auto [it, inserted] = _indices_dirs.emplace(key, std::unique_ptr<DorisFSDirectory>(dir));
63+
if (!inserted) {
64+
LOG(ERROR) << "InvertedIndexFileWriter::open attempted to insert a duplicate key: ("
65+
<< key.first << ", " << key.second << ")";
66+
LOG(ERROR) << "Directories already in map: ";
67+
for (const auto& entry : _indices_dirs) {
68+
LOG(ERROR) << "Key: (" << entry.first.first << ", " << entry.first.second << ")";
69+
}
70+
return ResultError(Status::InternalError(
71+
"InvertedIndexFileWriter::open attempted to insert a duplicate dir"));
72+
}
73+
6274
return dir;
6375
}
6476

0 commit comments

Comments
 (0)