fix: [2.5] avoid segmentation faults caused by retrieving empty vector datasets (#40546)

issue: #40544 
pr: #40545

Signed-off-by: xianliang.li <xianliang.li@zilliz.com>
pull/40728/head
foxspy 2025-03-18 14:58:13 +08:00 committed by GitHub
parent b0078ceae3
commit 0dc4b73c81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -333,6 +333,12 @@ VectorDiskAnnIndex<T>::GetVector(const DatasetPtr dataset) const {
PanicInfo(ErrorCode::UnexpectedError,
"failed to get vector, index is sparse");
}
// if dataset is empty, return empty vector
if (dataset->GetRows() == 0) {
return {};
}
auto res = index_.GetVectorByIds(dataset);
if (!res.has_value()) {
PanicInfo(ErrorCode::UnexpectedError,

View File

@ -483,6 +483,11 @@ VectorMemIndex<T>::GetVector(const DatasetPtr dataset) const {
"failed to get vector, index is sparse");
}
// if dataset is empty, return empty vector
if (dataset->GetRows() == 0) {
return {};
}
auto res = index_.GetVectorByIds(dataset);
if (!res.has_value()) {
PanicInfo(ErrorCode::UnexpectedError,