diff --git a/src/plugins/intel_cpu/src/config.cpp b/src/plugins/intel_cpu/src/config.cpp index 0c63b0d35464a4..6e317bac8265d8 100644 --- a/src/plugins/intel_cpu/src/config.cpp +++ b/src/plugins/intel_cpu/src/config.cpp @@ -69,8 +69,18 @@ void Config::readProperties(const ov::AnyMap& prop, const ModelType modelType) { threads = streamExecutorConfig.get_threads(); threadsPerStream = streamExecutorConfig.get_threads_per_stream(); if (key == ov::num_streams.name()) { - ov::Any value = val.as(); - auto streams_value = value.as(); + // Handle both numeric and string types safely to avoid unsafe iostream conversions + ov::Any streamValue; + if (val.is()) { + streamValue = val; // Already a string, use directly + } else if (val.is()) { + streamValue = std::to_string(val.as()); + } else if (val.is()) { + streamValue = std::to_string(val.as()); + } else { + streamValue = val; // Let ov::Any handle other types + } + auto streams_value = streamValue.as(); if (streams_value == ov::streams::NUMA) { modelDistributionPolicy = {}; hintPerfMode = ov::hint::PerformanceMode::LATENCY; @@ -104,13 +114,23 @@ void Config::readProperties(const ov::AnyMap& prop, const ModelType modelType) { } } else if (key == ov::hint::num_requests.name()) { try { - ov::Any value = val.as(); - int val_i = value.as(); + // Handle both numeric and string types safely to avoid unsafe iostream conversions + int val_i = 0; + if (val.is()) { + ov::Any numValue = val; + val_i = numValue.as(); + } else if (val.is()) { + val_i = static_cast(val.as()); + } else if (val.is()) { + val_i = val.as(); + } else { + val_i = val.as(); // Let ov::Any handle conversion + } OPENVINO_ASSERT(val_i >= 0, "invalid value."); hintNumRequests = static_cast(val_i); } catch (const ov::Exception&) { OPENVINO_THROW("Wrong value ", - val.as(), + val.is() ? val.as() : std::to_string(val_i), "for property key ", ov::hint::num_requests.name(), ". Expected only >= 0.");