From 20649a368a67126e78fdc795d20a147d008001d2 Mon Sep 17 00:00:00 2001 From: Michael Paul <31833332+MickeyPvX@users.noreply.github.com> Date: Thu, 21 May 2026 11:01:12 -0400 Subject: [PATCH] fix: resize Segment data_ to match capacity in ConcurrentArrayInvertedLists 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> --- .../faiss/faiss/cppcontrib/knowhere/invlists/InvertedLists.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thirdparty/faiss/faiss/cppcontrib/knowhere/invlists/InvertedLists.h b/thirdparty/faiss/faiss/cppcontrib/knowhere/invlists/InvertedLists.h index 372c95116..df57e6f8f 100644 --- a/thirdparty/faiss/faiss/cppcontrib/knowhere/invlists/InvertedLists.h +++ b/thirdparty/faiss/faiss/cppcontrib/knowhere/invlists/InvertedLists.h @@ -162,7 +162,7 @@ struct ConcurrentArrayInvertedLists : ::faiss::InvertedLists, NormInvertedLists template struct Segment { Segment(size_t segment_size, size_t code_size) : segment_size_(segment_size), code_size_(code_size) { - data_.reserve(segment_size_ * code_size_); + data_.resize(segment_size_ * code_size_); } T& operator[](idx_t idx) { assert(idx < segment_size_);