Skip to content

Commit ccff47e

Browse files
authored
[Fix](inverted index) fix use after free when duplicate key in index dir when index file writer open index #42207 (#42301)
cherry pick from #42207
1 parent 036906f commit ccff47e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,27 @@ Result<DorisFSDirectory*> InvertedIndexFileWriter::open(const TabletIndex* index
5959
}
6060
if (exists) {
6161
LOG(ERROR) << "try to init a directory:" << lfs_index_path << " already exists";
62-
return ResultError(Status::InternalError("init_fulltext_index directory already exists"));
62+
return ResultError(
63+
Status::InternalError("InvertedIndexFileWriter::open directory already exists"));
6364
}
6465

6566
bool can_use_ram_dir = true;
6667
bool use_compound_file_writer = false;
6768
auto* dir = DorisFSDirectoryFactory::getDirectory(_lfs, lfs_index_path.c_str(),
6869
use_compound_file_writer, can_use_ram_dir,
6970
nullptr, _fs, index_path.c_str());
70-
_indices_dirs.emplace(std::make_pair(index_id, index_suffix),
71-
std::unique_ptr<DorisFSDirectory>(dir));
71+
auto key = std::make_pair(index_id, index_suffix);
72+
auto [it, inserted] = _indices_dirs.emplace(key, std::unique_ptr<DorisFSDirectory>(dir));
73+
if (!inserted) {
74+
LOG(ERROR) << "InvertedIndexFileWriter::open attempted to insert a duplicate key: ("
75+
<< key.first << ", " << key.second << ")";
76+
LOG(ERROR) << "Directories already in map: ";
77+
for (const auto& entry : _indices_dirs) {
78+
LOG(ERROR) << "Key: (" << entry.first.first << ", " << entry.first.second << ")";
79+
}
80+
return ResultError(Status::InternalError(
81+
"InvertedIndexFileWriter::open attempted to insert a duplicate dir"));
82+
}
7283
return dir;
7384
}
7485

0 commit comments

Comments
 (0)