Skip to content

VFS: CREATE_ALWAYS on a game directory, or a write below a game file, leaves an overlay entry that hides the original #577

Backlog

Description

@gta5all

Static read of crates/xcl/src/vfs.rs and vfs_hooks.rs on main (508a0c7). In the first two cases a write that Windows would refuse succeeds and leaves an overlay entry of the wrong kind. The overlay is persistent, so the damage outlasts the run.

  1. CREATE_ALWAYS on a game directory creates an overlay file that hides it (vfs.rs:585-593)

    • Only TRUNCATE_EXISTING has a directory check (:568-583). For CREATE_ALWAYS on a directory that exists only in the game folder, replaces_original is false (is_file()), prepare_write(rel, false) succeeds and the decision is Use(<overlay>\data). The native open then creates a regular file there.
    • Trigger: open_decision("G:\\data", GENERIC_WRITE, CREATE_ALWAYS, 0) on the test Fixture.
    • Result: afterwards is_dir("data") is false (:454 sees the overlay file first), so listing data\* gives ERROR_PATH_NOT_FOUND and writes below it fail. Expected: Decision::Fail(ERROR_ACCESS_DENIED) and no overlay entry, as in the TRUNCATE_EXISTING branch.
    • Suggested fix: before prepare_write, fail with ERROR_ACCESS_DENIED when disposition == CREATE_ALWAYS && !ov_entry && in_orig and the original is a directory.
  2. A write below a game file creates an overlay directory with that file's name (vfs.rs:512-516 prepare_write, :625-629 create_dir)

    • Both call create_dir_all on the overlay path without checking that the virtual parent is a directory. stage_write (:483-488) has such a check.
    • Trigger: open_decision("G:\\data\\hello.txt\\x.bin", GENERIC_WRITE, CREATE_ALWAYS, 0) or create_dir("data\\hello.txt\\sub").
    • Result: success, and <overlay>\data\hello.txt is now a directory. read_path_rel("data\\hello.txt") returns that directory, so the game file cannot be read until the overlay is cleaned. Expected: ERROR_PATH_NOT_FOUND, nothing created.
    • Suggested fix: walk the ancestors of rel and return ERROR_PATH_NOT_FOUND when one exists (overlay or visible original) and is not a directory, before prepare_write in the write branch and at the top of create_dir. Missing parents must stay allowed: the directories test expects create_dir("saves\\slot1") to work without saves.
  3. FindFirstFile on a mount root lists the host folders themselves (vfs_hooks.rs:988-1004), low impact

    • For G:\ the relative path is empty, so dir_rel and pattern are both empty and join returns the bare folder path. The search then finds the overlay folder and the game folder as entries.
    • Trigger: collect_game_entries(v, "", real_collect) returns Ok with an entry named like the game folder. Expected: ERROR_FILE_NOT_FOUND.
    • Suggested fix: if rel.is_empty() { return Err(vfs::ERROR_FILE_NOT_FOUND); } at the top of collect_game_entries.

Each trigger can be a unit test next to truncate_existing_validation_errors, with the same native CreateFileW reference call deciding the expected error code.

Not tested: nothing was built or run (read on Linux; no game files). The XCL side is traced through the code by hand; the expected Win32 error codes are from memory, not from a run. Not checked: whether a retail title does any of this. Open PR #316 touches vfs.rs for other reasons and does not cover these.

AI use: found and written with Claude Code (Claude Fable 5.2), static code review only, under human review.

Activity

  1. fladit123 commented on Nov 24, 2026

    @fladit123

    I'll investigate item 1 on native Windows, using synthetic temporary directories and CreateFileW as the reference.

    I'll focus on reproducing the CREATE_ALWAYS directory case, checking the expected Win32 error codes and verifying that a rejected operation leaves the overlay unchanged.

    I'll keep items 2 and 3 outside this initial scope.

    AI use: ChatGPT (GPT-6.2) assisted with issue selection and investigation planning.

  2. WebIdentity1 commented on Nov 24, 2026

    @WebIdentity1

    Draft #618, head c741a2a, addresses item 2 only: writes and directory creation beneath an existing virtual file must fail without creating overlay parents or hiding the original. Native Win32 returned error 3; both new rejection tests failed with the old runtime and passed with the fix. The third test preserves missing/deleted-parent recreation. Full candidate four-thread workspace: 687 passed / 1 existing CLAMP failure / 41 ignored, four explicit skips. Baseline parallel timeout and serial result, plus the existing focused truncate-test failure, are disclosed in the draft. Retail smoke is still needed.

    This excludes the CREATE_ALWAYS-on-directory case being investigated by @fladit123 and item 3. #316 touches VFS path classification; its current diff applies cleanly to this branch, but the combined tree was not run.

    AI use: Codex (GPT-6), investigation, implementation and native Windows validation.

  3. fladit123 commented on Nov 24, 2026

    @fladit123

    Item 1 is implemented in #644. The regression test fails on the original runtime and passes with the fix, matching native Win32 error codes.

    Full workspace validation on my RTX 4060: 688 passed, 0 failed, 41 ignored (two explicit wave64 capability skips).

    Items 2 and 3 remain outside my PR's scope. Independent AMD validation and both retail smoke runs have now passed, thanks to @eizispark. The results are documented in #644, and the PR description check is green.

    AI use: Codex (GPT-6) and ChatGPT (GPT-6.2) assisted with implementation, testing and reporting.

  4. pickles976 commented on Nov 24, 2026

    @pickles976

    Cross-run adjudication of the open PRs (2026-11-24, Linux cross-build + Wine 9; repros = the two case tests from each PR's head, applied to main and to each other's heads):

    head case 1 (search under a path element that is a file) case 2 (CREATE_ALWAYS on a directory) both pass?
    main ❌ host directory leaks as an entry ❌ host directory gets overwritten 0/2
    #618 ❌ still leaks ✅ fixed 1/2
    #644 ✅ fixed ❌ still overwrites 1/2

    So the two PRs are complementary, not competing — each passes exactly the case its own test encodes, and neither touches the other's path. Merging one leaves the other defect in. Their README edits collide in one line, trivially.

    There is also a third uncovered case: rel == "" (a search on the bare mount root) classifies FindFirstFileW("G:\\") as Game { rel: "" } and lists the host overlay/game directories as entries of the title's root. Fix + test in #763 — disjoint from both cases above. Suggest: merge all three (any order; only README lines conflict), then close #577 with the three-way map.

    Harness for repro: cross-build recipe in #520 (llvm-mingw linker, static libunwind), cargo test -p xcl --lib --target x86_64-pc-windows-gnu under Wine — note two of the module's tests need Wine ≥ 11 (they call CopyFile2, which Wine 9 lacks entirely; #175).

  5. pickles976 commented on Nov 24, 2026

    @pickles976

    Follow-up on the case-3 row: I opened #763 for it, but #761 (upipibi) landed the identical guard ~3 minutes earlier with a stronger test (compares against the live native FindFirstFileExW("C:\\") rather than a pinned expectation) — I closed mine as a duplicate. The merge recommendation stands with the names fixed: #618 + #644 + #761 covers all three cases of this issue; any pair leaves one defect in.

  6. emirduran707 commented on Nov 24, 2026

    @emirduran707
    Contributor

    One more case of the same kind, not covered by #618 (whose description keeps "automatic creation of missing directories") or #644: a write whose parent folder exists in neither the game folder nor the overlay succeeds and creates that folder. Read on main 47efa2e:

    • prepare_write (vfs.rs:512-516) runs create_dir_all on the overlay parent without checking that the parent exists in the merged view. This copy is needed when the parent exists only in the game folder, but not when it exists nowhere, or was removed (whited out).
    • So CreateFileW("G:\nodir\f.bin", GENERIC_WRITE, CREATE_ALWAYS), and OPEN_ALWAYS / CREATE_NEW (also with read access only), succeeds and creates nodir. Windows fails with ERROR_PATH_NOT_FOUND (3).
    • If nodir had been removed, commit_write → remove_whiteout brings the folder back, empty. Its original children stay hidden, because remove_whiteout pushes the whiteout down to them.
    • create_dir (vfs.rs:629) does the same through create_dir_all: CreateDirectoryW("G:\a\b") creates a missing a. The CreateDirectoryW docs say it fails with ERROR_PATH_NOT_FOUND when an intermediate folder does not exist.
    • stage_write (vfs.rs:484-487), used by copy and move, already checks the parent, so CreateFileW and CopyFileW disagree on the same path.

    Suggested fix: in prepare_write and create_dir, fail with ERROR_PATH_NOT_FOUND unless the virtual parent is a folder (is_dir(parent), the game root counting as one), before anything is created. This touches the same lines as #618, so it would best come after it.

    Not tested by running; found by reading the code (with Claude Code, Claude Opus 5.5, in an audit of the VFS against Win32), and checked against the lines above.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions