Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[Reference] OOB index validation for ScatterUpdate (#37352)

Enrico Galli09dd016a8e1d
diff --git a/src/core/reference/include/openvino/reference/scatter_update.hpp b/src/core/reference/include/openvino/reference/scatter_update.hpp
index b6850c5448d..ded4418c321 100644
--- a/src/core/reference/include/openvino/reference/scatter_update.hpp
+++ b/src/core/reference/include/openvino/reference/scatter_update.hpp
@@ -6,6 +6,7 @@
#include <numeric>
+#include "openvino/core/except.hpp"
#include "openvino/core/shape.hpp"
#include "openvino/reference/utils/coordinate_transform.hpp"
#include "openvino/util/math_util.hpp"
@@ -95,6 +96,14 @@ static void scatter_update(const char* input_data,
const size_t indices_idx =
std::inner_product(indices_cord.begin(), indices_cord.end(), indices_in_strides.begin(), uint64_t(0));
int64_t slice_index = indices[indices_idx];
+ const auto axis_size = data_shape[axis];
+ OPENVINO_ASSERT(slice_index >= 0 && static_cast<uint64_t>(slice_index) < axis_size,
+ "ScatterUpdate indices value ",
+ slice_index,
+ " is out of bounds for axis ",
+ axis,
+ " of size ",
+ axis_size);
Coordinate out_start_corner(data_shape.size(), 0);
Coordinate out_end_corner(data_shape);
diff --git a/src/plugins/template/tests/functional/op_reference/scatter_update.cpp b/src/plugins/template/tests/functional/op_reference/scatter_update.cpp
index 6760ab063dd..1b0975ae4b2 100644
--- a/src/plugins/template/tests/functional/op_reference/scatter_update.cpp
+++ b/src/plugins/template/tests/functional/op_reference/scatter_update.cpp
@@ -7,6 +7,7 @@
#include <vector>
#include "base_reference_test.hpp"
+#include "common_test_utils/test_assertions.hpp"
#include "gtest/gtest.h"
#include "openvino/op/parameter.hpp"
@@ -558,6 +559,12 @@ std::vector<ScatterUpdate3Params> generateScatterUpdateNegativeAxisParams() {
}
return combinedParams;
}
+
+class ReferenceScatterUpdate6LayerNegativeTest : public ReferenceScatterUpdate6LayerTest {};
+
+TEST_P(ReferenceScatterUpdate6LayerNegativeTest, CompareWithHardcodedRefs) {
+ OV_EXPECT_THROW(Exec(), ov::Exception, testing::HasSubstr("is out of bounds for axis"));
+}
} // namespace
INSTANTIATE_TEST_SUITE_P(smoke_ScatterUpdate_With_Hardcoded_Refs,
@@ -569,4 +576,19 @@ INSTANTIATE_TEST_SUITE_P(smoke_ScatterUpdate_Negative_Axis_With_Hardcoded_Refs,
ReferenceScatterUpdate6LayerTest,
::testing::ValuesIn(generateScatterUpdateNegativeAxisParams()),
ReferenceScatterUpdate6LayerTest::getTestCaseName);
+
+INSTANTIATE_TEST_SUITE_P(
+ smoke_ScatterUpdate_out_of_range_index_throws,
+ ReferenceScatterUpdate6LayerNegativeTest,
+ ::testing::Values(
+ Builder{}
+ .data({{3, 3}, ov::element::f32, std::vector<float>{0, 0, 0, 0, 0, 0, 0, 0, 0}})
+ .indices({{1, 2},
+ ov::element::Type_t::i64,
+ std::vector<int64_t>{1, static_cast<int64_t>(std::numeric_limits<int64_t>::max())}})
+ .updates({{1, 2, 3}, ov::element::f32, std::vector<float>{1.0f, 1.1f, 1.2f, 2.0f, 2.1f, 2.2f}})
+ .axis({{1}, ov::element::i64, std::vector<int64_t>{0}})
+ .expected({{3, 3}, ov::element::f32, std::vector<float>{0, 0, 0, 0, 0, 0, 0, 0, 0}})),
+ ReferenceScatterUpdate6LayerNegativeTest::getTestCaseName);
+
} // namespace reference_tests