diff --git a/onnxruntime/core/providers/openvino/backend_utils.cc b/onnxruntime/core/providers/openvino/backend_utils.cc index 2a3dde4e0c7a2..bb7d55cc00dda 100644 --- a/onnxruntime/core/providers/openvino/backend_utils.cc +++ b/onnxruntime/core/providers/openvino/backend_utils.cc @@ -83,7 +83,24 @@ std::istream& operator>>(std::istream& stream, SharedContext::SharedWeights::Met stream >> value.size; size_t num_dimensions; stream >> num_dimensions; - value.dimensions.resize(num_dimensions); + + if (stream.fail()) { + ORT_THROW("Error: Failed to read num_dimensions from stream."); + } + + constexpr size_t MAX_SAFE_DIMENSIONS = 1024; + + size_t safe_num_dimensions = num_dimensions; + + if(num_dimensions == 0 || safe_num_dimensions > MAX_SAFE_DIMENSIONS) { + ORT_THROW("Invalid number of dimensions provided."); + } + try { + value.dimensions.resize(safe_num_dimensions); + } catch (const std::bad_alloc&) { + ORT_THROW("Error: Memory allocation failed while resizing dimensions."); + } + for (auto& dim : value.dimensions) { stream >> dim; } @@ -235,23 +252,23 @@ int GetFirstAvailableDevice(SessionContext& session_context) { void FillOutputsWithConstantData(std::shared_ptr node, Ort::UnownedValue& out_tensor) { switch (node->get_element_type()) { case ov::element::Type_t::f32: { - FillOutputHelper(out_tensor, node); + FillOutputHelper(out_tensor, std::move(node)); break; } case ov::element::Type_t::boolean: { - FillOutputHelper(out_tensor, node); + FillOutputHelper(out_tensor, std::move(node)); break; } case ov::element::Type_t::i32: { - FillOutputHelper(out_tensor, node); + FillOutputHelper(out_tensor, std::move(node)); break; } case ov::element::Type_t::i64: { - FillOutputHelper(out_tensor, node); + FillOutputHelper(out_tensor, std::move(node)); break; } case ov::element::Type_t::f16: { - FillOutputHelper(out_tensor, node); + FillOutputHelper(out_tensor, std::move(node)); break; } default: diff --git a/onnxruntime/core/providers/openvino/backends/basic_backend.cc b/onnxruntime/core/providers/openvino/backends/basic_backend.cc index 4d294a298fdf5..5dfd1c367cd65 100644 --- a/onnxruntime/core/providers/openvino/backends/basic_backend.cc +++ b/onnxruntime/core/providers/openvino/backends/basic_backend.cc @@ -114,7 +114,7 @@ BasicBackend::BasicBackend(std::unique_ptr& model_pr if (!subgraph_context.has_dynamic_input_shape) { delete model_proto.release(); } - ov_model = CreateOVModel(model, session_context_, const_outputs_map_); + ov_model = CreateOVModel(std::move(model), session_context_, const_outputs_map_); } exe_network_ = OVCore::CompileModel( ov_model, hw_target, device_config, subgraph_context_.subgraph_name); @@ -141,7 +141,7 @@ BasicBackend::BasicBackend(std::unique_ptr& model_pr } }; } - inferRequestsQueue_ = std::unique_ptr(new InferRequestsQueue(exe_network_, num_infer_req, initializer)); + inferRequestsQueue_ = std::unique_ptr(new InferRequestsQueue(exe_network_, num_infer_req, std::move(initializer))); } bool BasicBackend::ValidateSubgraph(std::map>& const_outputs_map) { diff --git a/onnxruntime/core/providers/openvino/onnx_ctx_model_helper.cc b/onnxruntime/core/providers/openvino/onnx_ctx_model_helper.cc index 9c55614633b82..244ceaf56fe05 100644 --- a/onnxruntime/core/providers/openvino/onnx_ctx_model_helper.cc +++ b/onnxruntime/core/providers/openvino/onnx_ctx_model_helper.cc @@ -11,7 +11,7 @@ namespace onnxruntime { namespace openvino_ep { -EPCtxHandler::EPCtxHandler(std::string ov_sdk_version, const logging::Logger& logger) : openvino_sdk_version_(ov_sdk_version), logger_(logger) { +EPCtxHandler::EPCtxHandler(std::string ov_sdk_version, const logging::Logger& logger) : openvino_sdk_version_(std::move(ov_sdk_version)), logger_(logger) { epctx_model_ = Model::Create("ovep_context_model", false, logger_); } diff --git a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc index 7bd50e71935a8..22477611ce25b 100644 --- a/onnxruntime/core/providers/openvino/openvino_execution_provider.cc +++ b/onnxruntime/core/providers/openvino/openvino_execution_provider.cc @@ -257,7 +257,7 @@ common::Status OpenVINOExecutionProvider::Compile( } }; - node_compute_funcs.push_back(compute_info); + node_compute_funcs.push_back(std::move(compute_info)); if (!status.IsOK()) { break; diff --git a/onnxruntime/core/providers/openvino/openvino_provider_factory.cc b/onnxruntime/core/providers/openvino/openvino_provider_factory.cc index 40843be978d90..53a4be8fca021 100644 --- a/onnxruntime/core/providers/openvino/openvino_provider_factory.cc +++ b/onnxruntime/core/providers/openvino/openvino_provider_factory.cc @@ -160,7 +160,7 @@ void ParseProviderOptions([[maybe_unused]] ProviderInfo& result, [[maybe_unused] struct OpenVINOProviderFactory : IExecutionProviderFactory { OpenVINOProviderFactory(ProviderInfo provider_info, SharedContext& shared_context) - : provider_info_(provider_info), shared_context_(shared_context) {} + : provider_info_(std::move(provider_info)), shared_context_(shared_context) {} ~OpenVINOProviderFactory() override {} @@ -333,7 +333,7 @@ struct OpenVINO_Provider : Provider { if (pi.so_share_ep_contexts) { ov::AnyMap map; map["NPU_COMPILATION_MODE_PARAMS"] = "enable-wd-blockarg-input=true compute-layers-with-higher-precision=Sqrt,Power,ReduceSum"; - pi.load_config["NPU"] = map; + pi.load_config["NPU"] = std::move(map); } return std::make_shared(pi, shared_context_); diff --git a/onnxruntime/core/providers/openvino/ov_versions/capability.cc b/onnxruntime/core/providers/openvino/ov_versions/capability.cc index 3b9704d4a65ed..d56687f868c3d 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/capability.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/capability.cc @@ -32,7 +32,7 @@ GetCapability::GetCapability(const EPCtxHandler& ep_ctx_handler, const std::string device_type_param, const bool enable_qdq_optimizer) : ep_ctx_handler_(ep_ctx_handler), graph_viewer_(graph_viewer_param), - device_type_(device_type_param) { + device_type_(std::move(device_type_param)) { bool npu_qdq_optimizer_enabled = false; if (device_type_.find("NPU") != std::string::npos) { device_type_ = "CPU"; diff --git a/onnxruntime/core/providers/openvino/ov_versions/data_ops.h b/onnxruntime/core/providers/openvino/ov_versions/data_ops.h index b7ee5e6a9f9f2..cf7d834d6cfc7 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/data_ops.h +++ b/onnxruntime/core/providers/openvino/ov_versions/data_ops.h @@ -84,7 +84,7 @@ class DataOps { const std::string dev_id, const bool npu_qdq_optimizer_enabled) : graph_viewer_(graph_viewer_param), version_id_(ver), - device_id_(dev_id), + device_id_(std::move(dev_id)), npu_qdq_optimizer_enabled_(npu_qdq_optimizer_enabled) { populate_op_mode_supported(); populate_types_supported(); diff --git a/onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc b/onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc index 902dab8c04ed0..67799c12d4b5e 100644 --- a/onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc +++ b/onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc @@ -712,6 +712,8 @@ Status CreateModelWithStrippedQDQNodes(const GraphViewer& src_graph, // Will set inputs after deciding fate oif all internal and external initializers // accumulated_inputs container will store input of the original graph and initializer with ext data InlinedVector accumulated_inputs; + accumulated_inputs.reserve(dst_graph_inputs.size()); + // dst_graph.SetInputs(dst_graph_inputs); dst_graph.SetOutputs(dst_graph_outputs);