From f59c5219597948a5d451fd06e5bb46d8131c3ce2 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Tue, 9 May 2023 03:27:58 +0000 Subject: [PATCH] [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 Commit-Queue: Alexander Aprelev --- runtime/bin/file_win.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/runtime/bin/file_win.cc b/runtime/bin/file_win.cc index 9e2389bef89..762c65b7205 100644 --- a/runtime/bin/file_win.cc +++ b/runtime/bin/file_win.cc @@ -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);