Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use-after-free bug in nmslib engine query path #1305

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Features
* Add parent join support for lucene knn [#1182](https://github.com/opensearch-project/k-NN/pull/1182)
### Enhancements
### Bug Fixes
### Bug Fixes
* Fix use-after-free case on nmslib search path [#1305](https://github.com/opensearch-project/k-NN/pull/1305)
### Infrastructure
* Upgrade gradle to 8.4 [1289](https://github.com/opensearch-project/k-NN/pull/1289)
### Documentation
Expand Down
2 changes: 1 addition & 1 deletion jni/include/nmslib_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ namespace knn_jni {
struct IndexWrapper {
explicit IndexWrapper(const std::string& spaceType) {
// Index gets constructed with a reference to data (see above) but is otherwise unused
similarity::ObjectVector data;
space.reset(similarity::SpaceFactoryRegistry<float>::Instance().CreateSpace(spaceType, similarity::AnyParams()));
index.reset(similarity::MethodFactoryRegistry<float>::Instance().CreateMethod(false, "hnsw", spaceType, *space, data));
}
similarity::ObjectVector data;
std::unique_ptr<similarity::Space<float>> space;
std::unique_ptr<similarity::Index<float>> index;
};
Expand Down
11 changes: 11 additions & 0 deletions jni/tests/nmslib_wrapper_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
using ::testing::NiceMock;
using ::testing::Return;

TEST(NmslibIndexWrapperSearchTest, BasicAssertions) {
similarity::initLibrary();
knn_jni::nmslib_wrapper::IndexWrapper indexWrapper = knn_jni::nmslib_wrapper::IndexWrapper("l2");
int k = 10;
int dim = 2;
std::unique_ptr<float> rawQueryvector(new float[dim]);
std::unique_ptr<similarity::Object> queryObject(new similarity::Object(-1, -1, dim*sizeof(float), rawQueryvector.get()));
similarity::KNNQuery<float> knnQuery(*(indexWrapper.space), queryObject.get(), k);
indexWrapper.index->Search((similarity::KNNQuery<float> *)nullptr);
}

TEST(NmslibCreateIndexTest, BasicAssertions) {
// Initialize nmslib
similarity::initLibrary();
Expand Down
Loading