IntelLabs / IntelLabs/vdms

Potential Memory Leak in Labels in VCL

Open
#194 0 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
C++
Stars
93
Forks
34
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
in the discriptorset add and add_n_store functions labels are copied to a memory location that goes out of scope.

**Additional context**
Labels are added for descriptor set to store class ids (integer values) or some strings.

The labels are later used in the function classify for majority vote on the labels
void DescriptorSet::classify(DescDataArray descriptors, unsigned n, long *labels, unsigned quorum)

The labels are set with the descriptorset insert functions when labels are not null
- add(float *descriptors, unsigned n_descriptors, long *labels)"
- add_and_store(float *descriptors, unsigned n_descriptors, long *labels)

these are mapped to the corresponding functions for each engine supported (FAISS, FLINNG, TileDB)

E.g. Faiss Engine (similar behavior with other engines) add function when the labels are not null, it copies labels to an unused memory location without setting the correct data structure and then returns

https://github.com/intel-inersource/libraries.databases.visual.vdms/blob/a96e8e21fef9ca369cb106eed5c7e4963e23ad11/src/vcl/FaissDescriptorSet.cc#L100

if (labels != NULL) {
_label_ids.resize(_index->ntotal + n);
long *dst = _label_ids.data() + _index->ntotal;
std::memcpy(dst, labels, n * sizeof(long));
}

The appropriate functions to correctly set the labels should be called.

example:
void DescriptorSet::set_labels_map(LabelIdVector &ids, std::vector &labels) should be used to store the labels when the type of the labels is string and similar function (not implemented) for other types of labels.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.