Skip to content

Sync with Microsoft ONNX Runtime - 06042026#1027

Open
ai-fw-intg wants to merge 2 commits intoovep-developfrom
sync_msft_06042026
Open

Sync with Microsoft ONNX Runtime - 06042026#1027
ai-fw-intg wants to merge 2 commits intoovep-developfrom
sync_msft_06042026

Conversation

@ai-fw-intg
Copy link
Copy Markdown

Automated daily backmerge from ORT main to ovep-develop. No conflicts detected. Do NOT squash or rebase - use merge commit only.

Copilot AI and others added 2 commits April 4, 2026 14:37
…soft#27777)

### Description

Fixes the DLL import-name conversion logic in
`DetermineLoadLibraryError()` in
`onnxruntime/core/platform/windows/dll_load_error.cc`.

The changes:
- Replace `LoadLibrary(dll_name)` with `LoadLibraryW(...)` so the code
no longer passes a `const char*` import-table name to the wide-character
Windows API under `UNICODE` builds.
- Replace the naive `char*` to `std::wstring` construction with
`MultiByteToWideChar(CP_ACP, ...)`, which is appropriate for ANSI PE
import names.
- Handle conversion failures by skipping the import entry instead of
continuing with an invalid or empty converted name.
- Fix the follow-up buffer sizing issue in the conversion path by
allocating space for the terminating null, checking the conversion
result, and then resizing the `std::wstring` back down to exclude the
terminator.

These updates keep the change focused on the Windows DLL dependency
diagnostic path while ensuring the new conversion logic is memory-safe.

### Motivation and Context

The original code mixed narrow and wide string handling in a
Windows-specific path that reports missing dependent DLLs. Under
standard `UNICODE` builds, that could cause the dependency lookup to
fail because a narrow import name was effectively being passed to a
wide-character API.

The follow-up review also identified an off-by-one write risk in the
first version of the conversion fix: `MultiByteToWideChar(..., -1, ...)`
returns a length including the null terminator, so the destination
buffer must reserve space for that terminator before conversion. This
update corrects that issue and preserves the intended diagnostic
behavior.

### Test
```
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
git checkout tlwu/fix-dll-name-string-conversion-test
cd 测试目录
test_dll_load.cmd
```

Output is like
```
====== Caught expected error ======
[ONNXRuntimeError] : 1 : FAIL : Error loading "E:\git\onnxruntime\测试目录\test_main.dll" which depends on "missing_dep.dll" which is missing. (Error 126: "The specified module could not be found.")
===================================

✅ SUCCESS: The fix works! 'missing_dep.dll' is correctly identified and reported in the error message.
```

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
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.

3 participants