From 1042720fdf8f11675e948652dadc0eb74b1272c4 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Wed, 20 Nov 2024 16:07:26 -0800 Subject: [PATCH 1/4] Fix UNC paths If the input file was a network path then the raw path returned by GetFinalPathByHandle may return a UNC path. If so, and if the original path wasn't a UNC path, and the original path doesn't need normalization, we want to use the original path. --- src/native/corehost/hostmisc/pal.windows.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 06070b0b1d5da..88e73a6256169 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -898,8 +898,12 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging) } } - // Remove the \\?\ prefix, unless it is necessary or was already there - if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && + // Remove the UNC prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there + if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && !LongFile::ShouldNormalize(*path)) + { + str = *path; + } + else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && !LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size()))) { str.erase(0, LongFile::ExtendedPrefix.size()); From ecb5c7fe47e3529d73ccb5de1aec2b20e763cb34 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Fri, 6 Dec 2024 15:57:38 -0800 Subject: [PATCH 2/4] Use MAXPATH instead --- src/native/corehost/hostmisc/pal.windows.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 88e73a6256169..853f7c101e886 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -898,10 +898,11 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging) } } - // Remove the UNC prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there - if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && !LongFile::ShouldNormalize(*path)) + // Remove the UNC extend prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there + if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && str.length() > MAX_PATH) { - str = *path; + str.erase(0, LongFile::UNCExtendedPathPrefix.size()); + str.insert(0, LongFile::UNCPathPrefix); } else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && !LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size()))) From 8942484924c24e1855b84a8994c4ca3eae9fd9fd Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Sat, 7 Dec 2024 12:18:06 -0800 Subject: [PATCH 3/4] Update src/native/corehost/hostmisc/pal.windows.cpp Co-authored-by: Elinor Fung --- src/native/corehost/hostmisc/pal.windows.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index 853f7c101e886..f5982fd09be1e 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -898,8 +898,8 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging) } } - // Remove the UNC extend prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there - if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && str.length() > MAX_PATH) + // Remove the UNC extended prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there + if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && str.length() < MAX_PATH) { str.erase(0, LongFile::UNCExtendedPathPrefix.size()); str.insert(0, LongFile::UNCPathPrefix); From 8afca61de56bb7512637f15baabdd97606e4d0d3 Mon Sep 17 00:00:00 2001 From: Andy Gocke Date: Mon, 9 Dec 2024 16:19:01 -0800 Subject: [PATCH 4/4] Update src/native/corehost/hostmisc/pal.windows.cpp Co-authored-by: Elinor Fung --- src/native/corehost/hostmisc/pal.windows.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/native/corehost/hostmisc/pal.windows.cpp b/src/native/corehost/hostmisc/pal.windows.cpp index f5982fd09be1e..40999ab002fe2 100644 --- a/src/native/corehost/hostmisc/pal.windows.cpp +++ b/src/native/corehost/hostmisc/pal.windows.cpp @@ -901,8 +901,7 @@ bool pal::realpath(pal::string_t* path, bool skip_error_logging) // Remove the UNC extended prefix (\\?\UNC\) or extended prefix (\\?\) unless it is necessary or was already there if (LongFile::IsUNCExtended(str) && !LongFile::IsUNCExtended(*path) && str.length() < MAX_PATH) { - str.erase(0, LongFile::UNCExtendedPathPrefix.size()); - str.insert(0, LongFile::UNCPathPrefix); + str.replace(0, LongFile::UNCExtendedPathPrefix.size(), LongFile::UNCPathPrefix); } else if (LongFile::IsExtended(str) && !LongFile::IsExtended(*path) && !LongFile::ShouldNormalize(str.substr(LongFile::ExtendedPrefix.size())))