Sync with Microsoft ONNX Runtime - 06042026#1027
Open
ai-fw-intg wants to merge 2 commits intoovep-developfrom
Open
Sync with Microsoft ONNX Runtime - 06042026#1027ai-fw-intg wants to merge 2 commits intoovep-developfrom
ai-fw-intg wants to merge 2 commits intoovep-developfrom
Conversation
…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>
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.
Automated daily backmerge from ORT main to ovep-develop. No conflicts detected. Do NOT squash or rebase - use merge commit only.