Skip to content

Commit b56a3d5

Browse files
authored
Merge pull request #3328 from alpkn/master
Check intervals of labels array
2 parents 23c329e + 1523034 commit b56a3d5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

demos/common/cpp/models/src/classification_model.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ std::unique_ptr<ResultBase> ClassificationModel::postprocess(InferenceResult& in
4242

4343
result->topLabels.reserve(scoresTensor.get_size());
4444
for (size_t i = 0; i < scoresTensor.get_size(); ++i) {
45-
result->topLabels.emplace_back(indicesPtr[i], labels[indicesPtr[i]], scoresPtr[i]);
45+
int ind = indicesPtr[i];
46+
if (ind < 0 || ind >= labels.size()) {
47+
throw std::runtime_error("Invalid index for the class label is found during postprocessing");
48+
}
49+
result->topLabels.emplace_back(ind, labels[ind], scoresPtr[i]);
4650
}
4751

4852
return retVal;

0 commit comments

Comments
 (0)