From 008f8061b4cf6a71c8c6321e172ffa043c6ad48e Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 03:37:20 +0100 Subject: [PATCH 1/4] file_system: GetFullPathName keeps a GAME: path on GAME: --- docs/runtime_imports.md | 5 ++++ runtime/shims/file_system.cpp | 43 +++++++++++++++++++++++++++++++ runtime/test/file_system_test.cpp | 41 +++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md index 6487151af1..9fe5adfcc0 100644 --- a/docs/runtime_imports.md +++ b/docs/runtime_imports.md @@ -102,6 +102,11 @@ and the `api-ms-win-core-file-*` sets a GDK title links against. name, and hides deleted names, the marker folder and the copy folder. - A path that climbs above `GAME:` with `..`, or names another drive, fails with `ERROR_INVALID_NAME`, so a title cannot reach outside the package and the overlay. +- `GetFullPathNameA/W` answers a `GAME:` path as itself (one separator style, no `.` or `..`), because the host would + turn `GAME:\x` into `\GAME:\x`, which no longer names the game folder. Callers that make a path absolute + before opening it (Rust's `std::fs`, C++ `std::filesystem::absolute`) otherwise failed every `GAME:` open with + `ERROR_PATH_NOT_FOUND`. `G:` and `T:` already survive the host's answer. The C runtime's `_fullpath` calls the host + function inside the UCRT and is not covered. - `CreateDirectory*` makes the folder in the overlay. A name the title can already see, including a folder only the package has, fails with `ERROR_ALREADY_EXISTS`; a missing parent with `ERROR_PATH_NOT_FOUND`. diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 5b9f921995..261bb2a068 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp @@ -582,6 +582,47 @@ DWORD WINAPI get_file_attributes_a(LPCSTR name) { return get_file_attributes_w(wide.c_str()); } +// GetFullPathName on a "GAME:" path. The host function reads "GAME:\x" as a relative name and answers +// "\GAME:\x", which no longer names the console drive, so a caller that makes its path absolute +// before opening it (Rust's std::fs, std::filesystem::absolute) lost the game folder: every "GAME:" open failed +// with ERROR_PATH_NOT_FOUND while the same name through CreateFileW worked. A "GAME:" path is already absolute: it +// comes back with one separator style and no "." or ".." parts. Every other path goes to the host. +bool full_game_path(const wchar_t* name, std::wstring& full, bool& has_file_part) { + const std::wstring path = name; + size_t prefix_length = 0; + if (console_drive(path, prefix_length) != Drive::Game || prefix_length != kGamePrefixLength) return false; + std::vector parts; + if (parse_console(path, parts) != Parsed::Console) return false; + full = L"GAME:"; + for (const auto& part : parts) full += L'\\' + part; + has_file_part = !parts.empty(); + if (!has_file_part) full += L'\\'; + return true; +} + +DWORD WINAPI get_full_path_name_w(LPCWSTR name, DWORD length, LPWSTR buffer, LPWSTR* file_part) { + std::wstring full; + bool has_file_part = false; + if (!name || !full_game_path(name, full, has_file_part)) return ::GetFullPathNameW(name, length, buffer, file_part); + if (full.size() + 1 > length) return static_cast(full.size() + 1); // too small: the size with the NUL + std::wmemcpy(buffer, full.c_str(), full.size() + 1); + if (file_part) *file_part = has_file_part ? buffer + full.rfind(L'\\') + 1 : nullptr; + return static_cast(full.size()); +} + +DWORD WINAPI get_full_path_name_a(LPCSTR name, DWORD length, LPSTR buffer, LPSTR* file_part) { + std::wstring full; + bool has_file_part = false; + if (!name || !full_game_path(widen_ansi(name).c_str(), full, has_file_part)) + return ::GetFullPathNameA(name, length, buffer, file_part); + const int needed = WideCharToMultiByte(CP_ACP, 0, full.c_str(), -1, nullptr, 0, nullptr, nullptr); // with the NUL + if (needed <= 0) return 0; + if (static_cast(needed) > length) return static_cast(needed); + WideCharToMultiByte(CP_ACP, 0, full.c_str(), -1, buffer, needed, nullptr, nullptr); + if (file_part) *file_part = has_file_part ? std::strrchr(buffer, '\\') + 1 : nullptr; + return static_cast(needed - 1); +} + BOOL WINAPI get_file_attributes_ex_w(LPCWSTR name, GET_FILEEX_INFO_LEVELS level, LPVOID info) { if (!name || !info) { SetLastError(ERROR_INVALID_PARAMETER); @@ -1106,6 +1147,8 @@ using namespace rt::fs; {dll, "FindNextFileW", reinterpret_cast(&find_next_file_w)}, \ {dll, "FindClose", reinterpret_cast(&find_close)}, \ {dll, "GetFileAttributesA", reinterpret_cast(&get_file_attributes_a)}, \ + {dll, "GetFullPathNameA", reinterpret_cast(&get_full_path_name_a)}, \ + {dll, "GetFullPathNameW", reinterpret_cast(&get_full_path_name_w)}, \ {dll, "GetFileAttributesW", reinterpret_cast(&get_file_attributes_w)}, \ {dll, "GetFileAttributesExA", reinterpret_cast(&get_file_attributes_ex_a)}, \ {dll, "GetFileAttributesExW", reinterpret_cast(&get_file_attributes_ex_w)}, \ diff --git a/runtime/test/file_system_test.cpp b/runtime/test/file_system_test.cpp index f51dd32e02..94fb2c5c74 100644 --- a/runtime/test/file_system_test.cpp +++ b/runtime/test/file_system_test.cpp @@ -46,6 +46,8 @@ using CopyFileExWFn = BOOL(WINAPI*)(LPCWSTR, LPCWSTR, LPPROGRESS_ROUTINE, LPVOID using CopyFile2Fn = HRESULT(WINAPI*)(PCWSTR, PCWSTR, COPYFILE2_EXTENDED_PARAMETERS*); using SetFileAttributesWFn = BOOL(WINAPI*)(LPCWSTR, DWORD); using SetFileAttributesAFn = BOOL(WINAPI*)(LPCSTR, DWORD); +using GetFullPathNameWFn = DWORD(WINAPI*)(LPCWSTR, DWORD, LPWSTR, LPWSTR*); +using GetFullPathNameAFn = DWORD(WINAPI*)(LPCSTR, DWORD, LPSTR, LPSTR*); int g_checks = 0; int g_failures = 0; @@ -698,6 +700,45 @@ int main() { rt::fs::configure(package, overlay); } + // A caller that makes its path absolute before opening it (Rust's std::fs, std::filesystem::absolute) goes through + // GetFullPathName. The host reads "GAME:\x" as a relative name and answers "\GAME:\x", so the + // open that follows never reached the game folder: "GAME:\a\b\c.bin" failed with ERROR_PATH_NOT_FOUND + // while the same name through CreateFileW opened. + { + write_path(package / "nested" / "deeper" / "c.bin", "deep"); + const auto full_w = resolve("kernel32.dll", "GetFullPathNameW"); + const auto full_a = resolve("kernel32.dll", "GetFullPathNameA"); + check(full_w && full_a, "kernel32.dll serves GetFullPathNameW and GetFullPathNameA"); + if (full_w && full_a) { + wchar_t full[MAX_PATH] = {}; + wchar_t* file_part = nullptr; + const DWORD n = full_w(L"GAME:/nested/./deeper/../deeper/c.bin", MAX_PATH, full, &file_part); + check(n == 25 && std::wstring(full) == L"GAME:\\nested\\deeper\\c.bin", "GetFullPathNameW keeps a GAME: path on GAME:, normalized"); + check(file_part && std::wstring(file_part) == L"c.bin", "and points the file part at the last name"); + HANDLE h = create_w(full, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); + check(h != INVALID_HANDLE_VALUE && read_handle(h) == "deep", "so the path it answers still opens the package file"); + if (h != INVALID_HANDLE_VALUE) ::CloseHandle(h); + check(full_w(L"GAME:\\nested\\deeper\\c.bin", 5, full, nullptr) == 26, "a buffer that is too small gets the size with the NUL"); + check(full_w(L"game:", MAX_PATH, full, &file_part) == 6 && std::wstring(full) == L"GAME:\\" && file_part == nullptr, + "GAME: alone is the root with no file part"); + char narrow[MAX_PATH] = {}; + char* narrow_part = nullptr; + check(full_a("GAME:\\nested\\deeper\\c.bin", MAX_PATH, narrow, &narrow_part) == 25 && + std::string(narrow) == "GAME:\\nested\\deeper\\c.bin" && narrow_part && std::string(narrow_part) == "c.bin", + "GetFullPathNameA answers the same"); + + // Every other path is still the host's answer. + wchar_t host_ours[MAX_PATH] = {}; + wchar_t host_real[MAX_PATH] = {}; + const DWORD ours = full_w(L"relative\\x.txt", MAX_PATH, host_ours, nullptr); + const DWORD real = ::GetFullPathNameW(L"relative\\x.txt", MAX_PATH, host_real, nullptr); + check(ours == real && std::wstring(host_ours) == std::wstring(host_real), "a host path is answered by the host"); + // A GAME: path that climbs out of the drive is not made absolute here; the open refuses it. + const DWORD escaped = full_w(L"GAME:\\..\\x", MAX_PATH, full, nullptr); + check(escaped != 0 && std::wstring(full).rfind(L"GAME:", 0) != 0, "GAME:\\.. is left to the host, which does not call it a GAME: path"); + } + } + std::filesystem::remove_all(root); std::printf("%d check(s), %d failure(s)\n", g_checks, g_failures); return g_failures == 0 ? 0 : 1; From 236d40097199e8e9737f9d71ec8edbd5a79626bd Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 04:07:47 +0100 Subject: [PATCH 2/4] file_system: GetFullPathName keeps a trailing separator and refuses GAME: above the root --- runtime/shims/file_system.cpp | 34 +++++++++++++++------- runtime/test/file_system_test.cpp | 47 +++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 261bb2a068..88386d5110 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp @@ -586,24 +586,34 @@ DWORD WINAPI get_file_attributes_a(LPCSTR name) { // "\GAME:\x", which no longer names the console drive, so a caller that makes its path absolute // before opening it (Rust's std::fs, std::filesystem::absolute) lost the game folder: every "GAME:" open failed // with ERROR_PATH_NOT_FOUND while the same name through CreateFileW worked. A "GAME:" path is already absolute: it -// comes back with one separator style and no "." or ".." parts. Every other path goes to the host. -bool full_game_path(const wchar_t* name, std::wstring& full, bool& has_file_part) { +// comes back with one separator style and no "." or ".." parts, and a trailing separator stays, as Windows keeps it +// for "C:\foo\" (then there is no file part). A path that climbs above GAME:\ is refused with ERROR_INVALID_NAME, +// as CreateFileW refuses the same name, and never reaches the host. Every other path goes to the host. +enum class FullPath { NotGame, Refused, Answered }; + +FullPath full_game_path(const wchar_t* name, std::wstring& full, bool& has_file_part) { const std::wstring path = name; size_t prefix_length = 0; - if (console_drive(path, prefix_length) != Drive::Game || prefix_length != kGamePrefixLength) return false; + if (console_drive(path, prefix_length) != Drive::Game || prefix_length != kGamePrefixLength) return FullPath::NotGame; std::vector parts; - if (parse_console(path, parts) != Parsed::Console) return false; + if (parse_console(path, parts) != Parsed::Console) return FullPath::Refused; full = L"GAME:"; for (const auto& part : parts) full += L'\\' + part; - has_file_part = !parts.empty(); - if (!has_file_part) full += L'\\'; - return true; + const bool trailing_separator = !path.empty() && is_separator(path.back()); + if (parts.empty() || trailing_separator) full += L'\\'; + has_file_part = !parts.empty() && !trailing_separator; + return FullPath::Answered; } DWORD WINAPI get_full_path_name_w(LPCWSTR name, DWORD length, LPWSTR buffer, LPWSTR* file_part) { std::wstring full; bool has_file_part = false; - if (!name || !full_game_path(name, full, has_file_part)) return ::GetFullPathNameW(name, length, buffer, file_part); + const FullPath kind = name ? full_game_path(name, full, has_file_part) : FullPath::NotGame; + if (kind == FullPath::NotGame) return ::GetFullPathNameW(name, length, buffer, file_part); + if (kind == FullPath::Refused) { + SetLastError(ERROR_INVALID_NAME); + return 0; + } if (full.size() + 1 > length) return static_cast(full.size() + 1); // too small: the size with the NUL std::wmemcpy(buffer, full.c_str(), full.size() + 1); if (file_part) *file_part = has_file_part ? buffer + full.rfind(L'\\') + 1 : nullptr; @@ -613,8 +623,12 @@ DWORD WINAPI get_full_path_name_w(LPCWSTR name, DWORD length, LPWSTR buffer, LPW DWORD WINAPI get_full_path_name_a(LPCSTR name, DWORD length, LPSTR buffer, LPSTR* file_part) { std::wstring full; bool has_file_part = false; - if (!name || !full_game_path(widen_ansi(name).c_str(), full, has_file_part)) - return ::GetFullPathNameA(name, length, buffer, file_part); + const FullPath kind = name ? full_game_path(widen_ansi(name).c_str(), full, has_file_part) : FullPath::NotGame; + if (kind == FullPath::NotGame) return ::GetFullPathNameA(name, length, buffer, file_part); + if (kind == FullPath::Refused) { + SetLastError(ERROR_INVALID_NAME); + return 0; + } const int needed = WideCharToMultiByte(CP_ACP, 0, full.c_str(), -1, nullptr, 0, nullptr, nullptr); // with the NUL if (needed <= 0) return 0; if (static_cast(needed) > length) return static_cast(needed); diff --git a/runtime/test/file_system_test.cpp b/runtime/test/file_system_test.cpp index 94fb2c5c74..f72ba570ab 100644 --- a/runtime/test/file_system_test.cpp +++ b/runtime/test/file_system_test.cpp @@ -733,9 +733,50 @@ int main() { const DWORD ours = full_w(L"relative\\x.txt", MAX_PATH, host_ours, nullptr); const DWORD real = ::GetFullPathNameW(L"relative\\x.txt", MAX_PATH, host_real, nullptr); check(ours == real && std::wstring(host_ours) == std::wstring(host_real), "a host path is answered by the host"); - // A GAME: path that climbs out of the drive is not made absolute here; the open refuses it. - const DWORD escaped = full_w(L"GAME:\\..\\x", MAX_PATH, full, nullptr); - check(escaped != 0 && std::wstring(full).rfind(L"GAME:", 0) != 0, "GAME:\\.. is left to the host, which does not call it a GAME: path"); + // Empty string: the host's answer (0), not a GAME: path. + wchar_t empty_ours[4] = {1}, empty_real[4] = {1}; + check(full_w(L"", 4, empty_ours, nullptr) == ::GetFullPathNameW(L"", 4, empty_real, nullptr), + "an empty name is answered by the host"); + + // A trailing separator stays and leaves no file part, as GetFullPathNameW(L"C:\\foo\\") does; a trailing "." does not. + file_part = nullptr; + check(full_w(L"GAME:\\nested\\", MAX_PATH, full, &file_part) == 13 && std::wstring(full) == L"GAME:\\nested\\" && + file_part == nullptr, + "a trailing separator is kept and there is no file part"); + check(full_w(L"GAME:/nested/./", MAX_PATH, full, &file_part) == 13 && std::wstring(full) == L"GAME:\\nested\\" && + file_part == nullptr, + "\".\\\" before a trailing separator does not remove it"); + check(full_w(L"GAME:\\nested\\.", MAX_PATH, full, &file_part) == 12 && std::wstring(full) == L"GAME:\\nested" && + file_part && std::wstring(file_part) == L"nested", + "a trailing \".\" removes itself, not the folder name"); + check(full_w(L"GAME:\\nested\\..\\", MAX_PATH, full, &file_part) == 6 && std::wstring(full) == L"GAME:\\" && + file_part == nullptr, + "a folder left with \"..\\\" is the root"); + check(full_a("GAME:\\nested\\", MAX_PATH, narrow, &narrow_part) == 13 && std::string(narrow) == "GAME:\\nested\\" && + narrow_part == nullptr, + "GetFullPathNameA keeps the trailing separator too"); + check(full_a("GAME:\\nested\\deeper\\c.bin", 5, narrow, &narrow_part) == 26, + "GetFullPathNameA with a small buffer answers the size with the NUL"); + + // A path that climbs above GAME:\ is refused the way CreateFileW refuses the same name (ERROR_INVALID_NAME), and + // never reaches the host: Windows would clamp "C:\..\x" at the drive root, but the open of "GAME:\..\x" fails, and + // an answer that opens something else than the open would is worse than none. + for (const wchar_t* climbing : {L"GAME:\\..", L"GAME:\\..\\x", L"GAME:\\nested\\..\\..\\x", L"game:/../x"}) { + wchar_t untouched[MAX_PATH] = L"untouched"; + SetLastError(0); + const bool refused = full_w(climbing, MAX_PATH, untouched, nullptr) == 0 && GetLastError() == ERROR_INVALID_NAME && + std::wstring(untouched) == L"untouched"; + SetLastError(0); + const bool same_as_open = create_w(climbing, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr) == + INVALID_HANDLE_VALUE && + GetLastError() == ERROR_INVALID_NAME; + check(refused && same_as_open, "a GAME: path above the root is refused by GetFullPathNameW as CreateFileW refuses it"); + } + SetLastError(0); + char narrow_untouched[MAX_PATH] = "untouched"; + check(full_a("GAME:\\..\\x", MAX_PATH, narrow_untouched, nullptr) == 0 && GetLastError() == ERROR_INVALID_NAME && + std::string(narrow_untouched) == "untouched", + "GetFullPathNameA refuses it too"); } } From 70ccae8510937856790109108479a9ae383d9ef3 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 04:19:15 +0100 Subject: [PATCH 3/4] file_system: GetFullPathName clears lpFilePart when it fails or the buffer is too small --- runtime/shims/file_system.cpp | 2 ++ runtime/test/file_system_test.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 88386d5110..0f92339d77 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp @@ -610,6 +610,7 @@ DWORD WINAPI get_full_path_name_w(LPCWSTR name, DWORD length, LPWSTR buffer, LPW bool has_file_part = false; const FullPath kind = name ? full_game_path(name, full, has_file_part) : FullPath::NotGame; if (kind == FullPath::NotGame) return ::GetFullPathNameW(name, length, buffer, file_part); + if (file_part) *file_part = nullptr; // as when the host fails or the buffer is too small: no file part if (kind == FullPath::Refused) { SetLastError(ERROR_INVALID_NAME); return 0; @@ -625,6 +626,7 @@ DWORD WINAPI get_full_path_name_a(LPCSTR name, DWORD length, LPSTR buffer, LPSTR bool has_file_part = false; const FullPath kind = name ? full_game_path(widen_ansi(name).c_str(), full, has_file_part) : FullPath::NotGame; if (kind == FullPath::NotGame) return ::GetFullPathNameA(name, length, buffer, file_part); + if (file_part) *file_part = nullptr; if (kind == FullPath::Refused) { SetLastError(ERROR_INVALID_NAME); return 0; diff --git a/runtime/test/file_system_test.cpp b/runtime/test/file_system_test.cpp index f72ba570ab..ae085d87b9 100644 --- a/runtime/test/file_system_test.cpp +++ b/runtime/test/file_system_test.cpp @@ -758,6 +758,21 @@ int main() { check(full_a("GAME:\\nested\\deeper\\c.bin", 5, narrow, &narrow_part) == 26, "GetFullPathNameA with a small buffer answers the size with the NUL"); + // lpFilePart is NULL when the buffer is too small and when the name is refused, not left as the caller had it + // (Wine's GetFullPathNameW, which the Windows function follows here). + wchar_t* sentinel_w = reinterpret_cast(1); + char* sentinel_a = reinterpret_cast(1); + check(full_w(L"GAME:\\nested\\deeper\\c.bin", 5, full, &sentinel_w) == 26 && sentinel_w == nullptr, + "a buffer that is too small clears the file part (W)"); + check(full_a("GAME:\\nested\\deeper\\c.bin", 5, narrow, &sentinel_a) == 26 && sentinel_a == nullptr, + "a buffer that is too small clears the file part (A)"); + sentinel_w = reinterpret_cast(1); + sentinel_a = reinterpret_cast(1); + check(full_w(L"GAME:\\..\\x", MAX_PATH, full, &sentinel_w) == 0 && sentinel_w == nullptr, + "a refused name clears the file part (W)"); + check(full_a("GAME:\\..\\x", MAX_PATH, narrow, &sentinel_a) == 0 && sentinel_a == nullptr, + "a refused name clears the file part (A)"); + // A path that climbs above GAME:\ is refused the way CreateFileW refuses the same name (ERROR_INVALID_NAME), and // never reaches the host: Windows would clamp "C:\..\x" at the drive root, but the open of "GAME:\..\x" fails, and // an answer that opens something else than the open would is worse than none. From 2f2869f4dab519d88c11dfc51599569096796e59 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 11:38:57 +0100 Subject: [PATCH 4/4] file_system: GetFullPathName with a NULL buffer is a size query; set the error when the ANSI conversion fails --- runtime/shims/file_system.cpp | 9 ++++++--- runtime/test/file_system_test.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 0f92339d77..7e66cb49fb 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp @@ -615,7 +615,7 @@ DWORD WINAPI get_full_path_name_w(LPCWSTR name, DWORD length, LPWSTR buffer, LPW SetLastError(ERROR_INVALID_NAME); return 0; } - if (full.size() + 1 > length) return static_cast(full.size() + 1); // too small: the size with the NUL + if (!buffer || full.size() + 1 > length) return static_cast(full.size() + 1); // size query or too small: the size with the NUL std::wmemcpy(buffer, full.c_str(), full.size() + 1); if (file_part) *file_part = has_file_part ? buffer + full.rfind(L'\\') + 1 : nullptr; return static_cast(full.size()); @@ -632,8 +632,11 @@ DWORD WINAPI get_full_path_name_a(LPCSTR name, DWORD length, LPSTR buffer, LPSTR return 0; } const int needed = WideCharToMultiByte(CP_ACP, 0, full.c_str(), -1, nullptr, 0, nullptr, nullptr); // with the NUL - if (needed <= 0) return 0; - if (static_cast(needed) > length) return static_cast(needed); + if (needed <= 0) { + if (GetLastError() == ERROR_SUCCESS) SetLastError(ERROR_NO_UNICODE_TRANSLATION); // never fail with a stale or zero error + return 0; + } + if (!buffer || static_cast(needed) > length) return static_cast(needed); // size query or too small WideCharToMultiByte(CP_ACP, 0, full.c_str(), -1, buffer, needed, nullptr, nullptr); if (file_part) *file_part = has_file_part ? std::strrchr(buffer, '\\') + 1 : nullptr; return static_cast(needed - 1); diff --git a/runtime/test/file_system_test.cpp b/runtime/test/file_system_test.cpp index ae085d87b9..d14036dc10 100644 --- a/runtime/test/file_system_test.cpp +++ b/runtime/test/file_system_test.cpp @@ -758,6 +758,12 @@ int main() { check(full_a("GAME:\\nested\\deeper\\c.bin", 5, narrow, &narrow_part) == 26, "GetFullPathNameA with a small buffer answers the size with the NUL"); + // A NULL buffer is a size query, however long the length says it is: the size with the NUL, nothing written. + wchar_t* query_part = reinterpret_cast(1); + check(full_w(L"GAME:\\nested\\deeper\\c.bin", MAX_PATH, nullptr, &query_part) == 26 && query_part == nullptr, + "GetFullPathNameW with a NULL buffer is a size query"); + check(full_a("GAME:\\nested\\deeper\\c.bin", MAX_PATH, nullptr, nullptr) == 26, "GetFullPathNameA with a NULL buffer is a size query"); + // lpFilePart is NULL when the buffer is too small and when the name is refused, not left as the caller had it // (Wine's GetFullPathNameW, which the Windows function follows here). wchar_t* sentinel_w = reinterpret_cast(1);