Fix non-ASCII Unicode model path crash across session and provider code#27724
Merged
yuslepukhin merged 2 commits intomicrosoft:mainfrom Mar 23, 2026
Merged
Conversation
On Windows, std::filesystem::path::string() converts the internal UTF-16 representation to a narrow string using the system's active ANSI code page. When the path contains characters outside that code page (Japanese, Chinese, Korean, etc.), this throws std::system_error with 'No mapping for the Unicode character exists in the target multi-byte code page.' This affected both the core session telemetry logging (causing InferenceSession::Initialize() to fail) and execution provider code (OpenVINO, TensorRT, TensorRT RTX, QNN, MIGraphX) where model paths are converted for EPContext attributes and profiling. Fix: Replace .filename().string() with ToUTF8String(.filename().native()) which uses WideCharToMultiByte(CP_UTF8, ...) and handles all Unicode characters correctly. This pattern is already used elsewhere in the codebase for path-to-string conversions. Note: Two remaining instances in Linux-only code (cann_utils.cc, device_discovery.cc) are left as-is since .string() is safe on Linux where paths are already narrow strings. Fixes microsoft/WindowsAppSDK#6173 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes Windows crashes (and related EP telemetry/profiling issues) when model/library paths contain non-ASCII Unicode by converting filenames to UTF-8 safely instead of using std::filesystem::path::string().
Changes:
- Replaced
.filename().string()with UTF-8-safe conversions for model filenames in core session telemetry logging. - Updated multiple execution providers (TensorRT, TensorRT RTX, QNN, OpenVINO, MIGraphX) to use UTF-8-safe filename extraction for EPContext/profiling attributes.
- Updated environment EP library registration telemetry to log UTF-8-safe library filenames.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| onnxruntime/core/session/inference_session.cc | Avoids Windows Unicode-to-ANSI conversion crash when logging model filenames to telemetry. |
| onnxruntime/core/session/environment.cc | Avoids Windows Unicode-to-ANSI conversion crash when logging EP library filename during registration. |
| onnxruntime/core/providers/tensorrt/onnx_ctx_model_helper.cc | Uses UTF-8-safe model filename for EP context attributes. |
| onnxruntime/core/providers/qnn/builder/qnn_profile_serializer.cc | Uses UTF-8-safe output filename for QNN profiling log naming. |
| onnxruntime/core/providers/qnn/builder/onnx_ctx_model_helper.cc | Uses UTF-8-safe context cache filename for QNN EP context. |
| onnxruntime/core/providers/openvino/backend_manager.cc | Uses UTF-8-safe blob filename for OpenVINO EP context export. |
| onnxruntime/core/providers/nv_tensorrt_rtx/onnx_ctx_model_helper.cc | Uses UTF-8-safe engine/model filenames for TensorRT RTX EP context attributes. |
| onnxruntime/core/providers/migraphx/migraphx_execution_provider_utils.h | Uses UTF-8-safe model filename for MIGraphX graph ID logging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
yuslepukhin
reviewed
Mar 20, 2026
Standardize all filename-to-string conversions to use PathToUTF8String() consistently, as requested in review. Both PathToUTF8String and ToUTF8String are functionally identical, but using the path-specific helper uniformly improves readability for filesystem path operations.
Member
|
/azp run Linux QNN CI Pipeline, Win_TRT_Minimal_CUDA_Test_CI, Windows ARM64 QNN CI Pipeline, Windows GPU Doc Gen CI Pipeline |
|
Azure Pipelines successfully started running 4 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Windows,
std::filesystem::path::string()converts the internal UTF-16 representation to a narrow string using the system's active ANSI code page. When the path contains characters outside that code page (Japanese, Chinese, Korean, etc.), this throws std::system_error with 'No mapping for the Unicode character exists in the target multi-byte code page.'This affected both the core session telemetry logging (causing
InferenceSession::Initialize()to fail) and execution provider code (OpenVINO, TensorRT, TensorRT RTX, QNN, MIGraphX) where model paths are converted for EPContext attributes and profiling.Motivation and Context
Fix: Replace
.filename().string()withPathToUTF8String(.filename().native())which usesWideCharToMultiByte(CP_UTF8, ...)and handles all Unicode characters correctly. This pattern is already used elsewhere in the codebase for path-to-string conversions.Note: Two remaining instances in Linux-only code (
cann_utils.cc,device_discovery.cc) are left as-is since.string()is safe on Linux where paths are already narrow strings.Fixes microsoft/WindowsAppSDK#6173