Skip to content

Runtime: GetFullPathNameA/W keep a GAME: path on GAME: (Rust std::fs and std::filesystem::absolute could not open GAME: files) - #4621

Open
tedin7 wants to merge 3 commits into
ItsNotRexed:mainfrom
tedin7:game-nested-path
Open

tedin7 wants to merge 3 commits into
ItsNotRexed:mainfrom
tedin7:game-nested-path

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: new RT item, GetFullPathNameA/W for GAME: paths (#4571 (comment))

What and why

Any caller that makes a path absolute before opening it lost the game folder: std::fs::read("GAME:\\data\\x") in Rust, and std::filesystem::absolute or GetFullPathName in C++, failed with ERROR_PATH_NOT_FOUND. The same name through CreateFileW opened fine.

Cause: runtime/shims/file_system.cpp maps GAME: in the file calls but does not serve GetFullPathName. The host reads GAME:\data\x as a relative name and answers <current folder>\GAME:\data\x. The next CreateFileW then sees a host path with a GAME: folder name in it, and no shim recognises it. G:\data\x survives the host call because it is a normal drive letter, which is why G: worked and GAME: did not. It is not about nested folders: GAME:\data\hello.txt failed too.

Fix: GetFullPathNameA/W answer a GAME: path as itself, normalized (one separator style, no ./..), with the usual length and file-part contract. A trailing separator stays and leaves no file part, as Windows answers C:\foo\ (checked against Wine 11 with a small guest: C:\foo\ -> C:\foo\, file part NULL; C:\foo\. -> C:\foo, file part foo; C:\foo\..\ -> C:\). A GAME: path that climbs above the root (GAME:\..\x) is refused with ERROR_INVALID_NAME and never reaches the host: Windows clamps C:\..\x to C:\x, but the GAME: mapping of CreateFileW refuses the same name with ERROR_INVALID_NAME, and an answer that opens something the open would not is worse than none. Every other path (and an empty string) goes to the host; a NULL name is passed to the host as before.

Found with XCL's synthetic test title (its check "console paths G:\ and GAME:"), then reproduced without it: a small Rust program calling std::fs::read on five spellings, and a C++ guest calling CreateFileW and GetFullPathNameW on the same names. No XCL code, header or table is used here.

Tested

  • file_system_test (resolves the shims through the registry like the others): 26 new checks (175 in all). With the fix missing or partial the new checks fail (the last round: 4 failures, lpFilePart not cleared); with this fix 175 checks, 0 failures. Clang-cl/xwin cross build, run under Wine 11 on Linux. Not run on Windows.
  • lpFilePart is set to NULL when the buffer is too small and when a GAME: name is refused (Wine's GetFullPathNameW does the same for W; Wine's A variant leaves it untouched, here A clears it like W).
  • End to end with the Rust program under gta6rt --run: before, GAME:\data\hello.txt, GAME:\data\sub\nested.bin and game:/data/sub/nested.bin gave "Path not found (os error 3)"; after, all five spellings (G: and GAME:) read.
  • Reviewed twice by an independent model (DeepSeek) before opening: the first round found the GAME:.. escape and the lost trailing separator, the second the lpFilePart on failure; all three are fixed above with tests that fail before.
  • Not covered: names with trailing spaces or "..." parts, which Windows treats specially and this shim keeps as ordinary names (pre-existing in the GAME: mapping, same for CreateFileW).
  • Not covered: the UCRT's _fullpath calls GetFullPathNameW inside ucrtbase, past the shim (same class as CRT fopen).

Overlap

#3683 (file shims under three more API sets) edits the same FILE_API macro: the two new rows may need a rebase. No other open PR or claim mentions GetFullPathName (searched PR titles and all 23 coordination issues). #3651, #3955, #3962, #4512 touch file_system.cpp elsewhere.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs quoted here.
  • A new translator rule is in the contract table of docs/design.md. (No translator change.)

AI-assisted (Claude Code).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built and ran file_system_test at 70ccae85 on Windows 11: 175 checks, 0 failures, exit 0.

The new cases pass for both A and W forms: a GAME: path comes back as itself (separators normalised, ./.. resolved, trailing separator kept, file part set or null accordingly), a too-small buffer returns the size with the NUL and clears the file part, a refused name clears the file part, and a path that climbs above GAME:\ is ERROR_INVALID_NAME exactly as CreateFileW refuses it. Non-GAME: paths still go to the host functions. git diff --check clean. No blocking issue.

@iurysf

iurysf commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 70ccae8 on Windows 11, MSVC 14.44.35207 (cl 19.44.35215), Ninja RelWithDebInfo: file_system_test printed 175 check(s), 0 failure(s) and exited 0.

Negative control: full_game_path returned NotGame, so a GAME: name fell through to the host GetFullPathNameA/W. The same test then exited 1 with 20 failures, all of them the GAME: cases (normalized answer, file part, small buffer, trailing separator, and the above-root ERROR_INVALID_NAME checks). The host-path and empty-name checks still passed. Restored the source; the test passed again (175 checks, 0 failures).

AI-assisted (OpenBot team).

@Atomic258

Copy link
Copy Markdown

Tested head 70ccae85 — Windows, VS 2022 BuildTools + Ninja, RTX 5090 (driver 617.42), no game files: pass.

  • cmake --build runtime/build at this head: clean, all targets relinked.
  • ctest --test-dir runtime/build -R file_system --output-on-failure -> Passed (3.46s). The new GetFullPathNameA/W GAME:-path cases are exercised by that test (97 new lines in file_system_test.cpp).
  • git diff --check and scripts/check_no_game_data.py clean.
  • No negative control: rebuilding main's file_system.cpp would double the build for a shim-only check; the test file itself is new in this PR.

AI-assisted (Devin).

@tupacfan04

Copy link
Copy Markdown
Contributor

APPROVE. Mergeable and clean against origin/main (7b7d73f); built file_system_test (MSVC 14.51, /W4 /permissive-, no warnings) and 175/175 pass. Negative control: main's file_system.cpp with the PR test fails at "kernel32.dll serves GetFullPathNameW/A" (152/175). compileall clean.

Two minor gaps in the shim:

  • runtime/shims/file_system.cpp:619 calls wmemcpy(buffer, ...) without checking buffer != nullptr; GetFullPathNameW(name, big_len, NULL, ...) is a valid size query and would crash.
  • :634-636 returns 0 without SetLastError if WideCharToMultiByte fails.

Neither is covered by the new tests; a size-query case and a conversion-failure case would close them.

AI-assisted review, no game files, no GPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants