Skip to content

Commit 0edac9d

Browse files
authored
fix: resize Segment data_ to match capacity in ConcurrentArrayInvertedLists (#1641)
The Segment helper in ConcurrentArrayInvertedLists reserves data_'s capacity but never sizes it, so std::vector::size() stays 0 while operator[] reads and writes at offsets within capacity. That is undefined behavior; on a libstdc++ built with -D_GLIBCXX_ASSERTIONS, operator[] has a bounds check compiled in and the process aborts on the first growing-segment write (e.g. an IVF_FLAT_CC insert). Switch reserve() to resize() so size() == capacity() and operator[] is in-bounds. Same allocation, plus a zero-fill that the subsequent memcpy overwrites; no measurable runtime cost. Behavior on unhardened libstdc++ is unchanged. Signed-off-by: Michael Paul <31833332+MickeyPvX@users.noreply.github.com>
1 parent fca2aaf commit 0edac9d

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

thirdparty/faiss/faiss/cppcontrib/knowhere/invlists/InvertedLists.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct ConcurrentArrayInvertedLists : ::faiss::InvertedLists, NormInvertedLists
162162
template <typename T>
163163
struct Segment {
164164
Segment(size_t segment_size, size_t code_size) : segment_size_(segment_size), code_size_(code_size) {
165-
data_.reserve(segment_size_ * code_size_);
165+
data_.resize(segment_size_ * code_size_);
166166
}
167167
T& operator[](idx_t idx) {
168168
assert(idx < segment_size_);

0 commit comments

Comments
 (0)