Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix load failure for onnx model with external data and slash (/) in path [Windows] #11793

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions onnxruntime/core/platform/path_lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#ifdef _WIN32

#if _GAMING_XBOX
// Hacky, but the PathCch* APIs work on Xbox. Presumably PathCch.h needs to be updated to include the
// Hacky, but the PathCch* APIs work on Xbox. Presumably PathCch.h needs to be updated to include the
// GAMES partition. It would be worthwhile to investigate this a bit more (or just use std::filesystem).
#pragma push_macro("WINAPI_FAMILY")
#undef WINAPI_FAMILY
Expand Down Expand Up @@ -95,12 +95,16 @@ Status RemoveFileSpec(PWSTR pszPath, size_t cchPath) {
} // namespace

common::Status GetDirNameFromFilePath(const std::basic_string<ORTCHAR_T>& s, std::basic_string<ORTCHAR_T>& ret) {
std::wstring input = s;
if (input.empty()) {
if (s.empty()) {
ret = ORT_TSTR(".");
return Status::OK();
}

ret = s;

// Replace slash to backslash since we use PathCchRemoveBackslash
std::replace(ret.begin(), ret.end(), ORTCHAR_T('/'), ORTCHAR_T('\\'));

auto st = onnxruntime::RemoveFileSpec(const_cast<wchar_t*>(ret.data()), ret.length() + 1);
if (!st.IsOK()) {
std::ostringstream oss;
Expand Down
20 changes: 20 additions & 0 deletions onnxruntime/test/platform/path_lib_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ TEST(PathTest, windows_root) {
TEST(PathTest, root) {
PATH_EXPECT("\\", "\\");
}

TEST(PathTest, windows_slash_path_1) {
PATH_EXPECT("C:\\Windows", "C:/Windows/a.txt");
}

TEST(PathTest, windows_slash_path_2) {
PATH_EXPECT("C:\\Windows", "C:\\Windows/a.txt");
}

TEST(PathTest, windows_slash_path_3) {
PATH_EXPECT("C:\\Windows", "C:\\Windows//a.txt");
}

TEST(PathTest, windows_slash_path_4) {
PATH_EXPECT("C:\\Windows", "C:\\Windows\\\\system32/");
}

TEST(PathTest, windows_slash_path_5) {
PATH_EXPECT("C:\\Windows", "C:/Windows//system32/");
}
#else
TEST(PathTest, simple) {
PATH_EXPECT("/Windows", "/Windows/a.txt");
Expand Down