[vm/win] Leave \\?\UNC\ prefix when canonicalizing file path on Windows.

Fixes https://github.com/dart-lang/sdk/issues/52309
TEST=run tests\co19\src\LibTest\io\exit\exit_A01_t01.dart for example with UNC path to dart.exe

Change-Id: Ief6eb4cda24422a9a100abaf5173bb95e44d19bf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302060
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev
2023-05-09 03:27:58 +00:00
committed by Commit Queue
parent 941b50f3d8
commit f59c521959
+7 -2
View File
@@ -1057,11 +1057,16 @@ const char* File::GetCanonicalPath(Namespace* namespc,
ASSERT(result_size <= required_size - 1);
CloseHandle(file_handle);
// Remove leading \\?\ if possible, unless input used it.
// Remove leading \\?\ since it is only to overcome MAX_PATH limitation.
// Leave it if input used it though.
int offset = 0;
if ((result_size > 4) && (wcsncmp(path.get(), L"\\\\?\\", 4) == 0) &&
(strncmp(pathname, "\\\\?\\", 4) != 0)) {
offset = 4;
if ((result_size > 8) && (wcsncmp(path.get(), L"\\\\?\\UNC\\", 8) == 0)) {
// Leave '\\?\UNC\' prefix intact - stripping it makes invalid UNC name.
} else {
offset = 4;
}
}
int utf8_size = WideCharToMultiByte(CP_UTF8, 0, path.get() + offset, -1,
nullptr, 0, nullptr, nullptr);