Add check to avoid out of bounds segfault in scatterNDupdate (#17066)

* Add check to avoid out of bounds segfault in scatterNDupdate

* Fix code style
This commit is contained in:
Oleg Pipikin 2023-04-25 14:13:14 +02:00 committed by GitHub
parent 6e11645018
commit ab879f143c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -43,6 +43,8 @@ void scatterNdUpdate(const dataType* const inputData,
const auto update_data = updates + i * update_el_number;
const auto update_mem_size = update_el_number * sizeof(dataType);
OPENVINO_ASSERT(out_index >= 0 && out_index + update_el_number <= shape_size(dataShape),
"Index is out of bounds");
std::memcpy(outBuf + out_index, update_data, update_mem_size);
}
}

View File

@ -198,4 +198,53 @@ std::vector<ScatterNDUpdateParams> generateScatterNDUpdateCombinedParams() {
INSTANTIATE_TEST_SUITE_P(smoke_ScatterNDUpdate_With_Hardcoded_Refs, ReferenceScatterNDUpdateLayerTest,
testing::ValuesIn(generateScatterNDUpdateCombinedParams()), ReferenceScatterNDUpdateLayerTest::getTestCaseName);
class ReferenceScatterNDUpdateLayerNegativeTest : public ReferenceScatterNDUpdateLayerTest{
};
TEST_P(ReferenceScatterNDUpdateLayerNegativeTest, CompareWithRefsNegative) {
LoadNetwork();
FillInputs();
inferRequest = executableNetwork.create_infer_request();
const auto& functionParams = function->get_parameters();
for (size_t i = 0; i < functionParams.size(); ++i) {
inferRequest.set_tensor(executableNetwork.input(i), inputData[i]);
}
ASSERT_THROW(inferRequest.infer(), ov::Exception);
}
template <element::Type_t IN_ET, element::Type_t IU_ET>
std::vector<ScatterNDUpdateParams> generateScatterNDUpdateNegativeParams() {
using T = typename element_type_traits<IN_ET>::value_type;
using U = typename element_type_traits<IU_ET>::value_type;
std::vector<ScatterNDUpdateParams> scatterParams {
// scatter_nd_update_2x3_with_out_of_bounds_index
ScatterNDUpdateParams(reference_tests::Tensor({2, 3}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6}),
reference_tests::Tensor({1, 2}, IU_ET, std::vector<U>{1, 3}),
reference_tests::Tensor({1}, IN_ET, std::vector<T>{10}),
reference_tests::Tensor({2, 2}, IN_ET, std::vector<T>{1, 2, 3, 4, 5, 6}),
"scatter_nd_update_2x3_with_out_of_bounds_index"),
};
return scatterParams;
}
std::vector<ScatterNDUpdateParams> generateScatterNDUpdateCombinedNegativeParams() {
const std::vector<std::vector<ScatterNDUpdateParams>> scatterTypeParams {
generateScatterNDUpdateNegativeParams<element::Type_t::f32, element::Type_t::i64>()
};
std::vector<ScatterNDUpdateParams> combinedParams;
for (const auto& params : scatterTypeParams) {
combinedParams.insert(combinedParams.end(), params.begin(), params.end());
}
return combinedParams;
}
INSTANTIATE_TEST_SUITE_P(smoke_ScatterNDUpdate_With_Hardcoded_Refs, ReferenceScatterNDUpdateLayerNegativeTest,
testing::ValuesIn(generateScatterNDUpdateCombinedNegativeParams()), ReferenceScatterNDUpdateLayerNegativeTest::getTestCaseName);
} // namespace