Skip to content

Fix non-ASCII Unicode model path crash across session and provider code#27724

Merged
yuslepukhin merged 2 commits intomicrosoft:mainfrom
sagarbhure-msft:fix/unicode-model-path-telemetry
Mar 23, 2026
Merged

Fix non-ASCII Unicode model path crash across session and provider code#27724
yuslepukhin merged 2 commits intomicrosoft:mainfrom
sagarbhure-msft:fix/unicode-model-path-telemetry

Conversation

@sagarbhure-msft
Copy link
Copy Markdown
Contributor

@sagarbhure-msft sagarbhure-msft commented Mar 18, 2026

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() with PathToUTF8String(.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

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

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.
@yuslepukhin
Copy link
Copy Markdown
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
Copy link
Copy Markdown

Azure Pipelines successfully started running 4 pipeline(s).

Copy link
Copy Markdown
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@yuslepukhin yuslepukhin merged commit 3bb032e into microsoft:main Mar 23, 2026
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WinML ORT compile and inferenceSession error when the model path contains any non‑ASCII Unicode characters

3 participants