Skip to content

Commit 9d8fc43

Browse files
Copilothariharans29
andcommitted
Add bounds check for negative indices in ArrayFeatureExtractor
Co-authored-by: hariharans29 <9969784+hariharans29@users.noreply.github.com>
1 parent 0d8107b commit 9d8fc43

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

onnxruntime/core/providers/cpu/ml/array_feature_extractor.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ common::Status ArrayFeatureExtractorOp<T>::Compute(OpKernelContext* context) con
7373
}
7474

7575
for (int64_t i = 0; i < num_indices; ++i) {
76-
if (y_data[i] >= stride) {
76+
if (y_data[i] < 0 || y_data[i] >= stride) {
7777
return ORT_MAKE_STATUS(
7878
ONNXRUNTIME, INVALID_ARGUMENT,
79-
"Invalid Y argument: index is out of range: Y[", i, "] (", y_data[i], ") >=", stride);
79+
"Invalid Y argument: index is out of range: Y[", i, "] (", y_data[i], ") must be in [0,", stride, ")");
8080
}
8181
}
8282

onnxruntime/test/providers/cpu/ml/array_feature_extractor_test.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,12 @@ TEST_F(ArrayFeatureExtractorTest, InvalidInputOutOfBoundsY) {
109109
test_.Run(OpTester::ExpectResult::kExpectFailure);
110110
}
111111

112+
TEST_F(ArrayFeatureExtractorTest, InvalidInputNegativeY) {
113+
test_.AddInput<int64_t>("X", {10, 1}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
114+
test_.AddInput<int64_t>("Y", {1}, {-10});
115+
test_.AddOutput<int64_t>("Z", {0}, {});
116+
test_.Run(OpTester::ExpectResult::kExpectFailure);
117+
}
118+
112119
} // namespace test
113120
} // namespace onnxruntime

0 commit comments

Comments
 (0)