Skip to content

Commit e39360a

Browse files
authored
fix(search-buffer): ASan heap-buffer-underflow in SearchBuffer::can_skip (#241)
ASan will be added in #239. It flags `SearchBuffer::can_skip`. Here we reorder the logic to check `full()` before accessing `back()`. Accessing `back()` on an empty buffer caused an index underflow (`SIZE_MAX`).
1 parent f980d75 commit e39360a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/svs/index/vamana/search_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ template <typename Idx, typename Cmp = std::less<>> class SearchBuffer {
340340
/// returns ``true``.
341341
///
342342
bool can_skip(float distance) const {
343-
return compare_(back().distance(), distance) && full();
343+
return full() && (capacity() == 0 || compare_(back().distance(), distance));
344344
}
345345

346346
///

0 commit comments

Comments
 (0)