Skip to content

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

[Transformations] Fix vector subscript out of range in transformations (#27180)

Pawel Raaszd96bd7d9525e
diff --git a/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp b/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp
index f0de55f4028..d86b4b71f10 100644
--- a/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp
+++ b/src/common/transformations/src/transformations/common_optimizations/remove_multi_subgraph_op_dangling_params.cpp
@@ -178,19 +178,21 @@ bool ov::pass::RemoveMultiSubGraphOpDanglingParamsResults::run_on_model(const st
if (std::count(std::begin(to_remove_descriptors_indexes[body_idx]),
std::end(to_remove_descriptors_indexes[body_idx]),
desc_idx) > 0) {
- auto& body_param = body_params[body_in_descriptors[desc_idx]->m_body_parameter_index];
- body_func->remove_parameter(body_param);
- // Move all body indexes which are after these indicated by to_remove_descriptors_indexes
- update_body_param_desc(body_in_descriptors,
- body_in_descriptors[desc_idx]->m_body_parameter_index);
+ if (body_in_descriptors[desc_idx]->m_body_parameter_index < body_params.size()) {
+ auto& body_param = body_params[body_in_descriptors[desc_idx]->m_body_parameter_index];
+ body_func->remove_parameter(body_param);
+ // Move all body indexes which are after these indicated by to_remove_descriptors_indexes
+ update_body_param_desc(body_in_descriptors,
+ body_in_descriptors[desc_idx]->m_body_parameter_index);
+ }
// remove dangling input of MultiSubGraphOp which was not removed earlier
auto current_input_idx = body_in_descriptors[desc_idx]->m_input_index;
- auto& current_input = op_inputs[current_input_idx];
// the same input tensor can go to different input ports
- if (std::count(std::begin(required_inputs_indices),
+ if (current_input_idx < op_inputs.size() &&
+ std::count(std::begin(required_inputs_indices),
std::end(required_inputs_indices),
current_input_idx) == 0 &&
- std::count(std::begin(op_inputs), std::end(op_inputs), current_input) > 0) {
+ std::count(std::begin(op_inputs), std::end(op_inputs), op_inputs[current_input_idx]) > 0) {
op_inputs.erase(std::next(op_inputs.begin(), current_input_idx));
// Move all input indexes (in all bodies) which are after these indicated by
// to_remove_descriptors_indexes and are not used in any body