Skip to content

RT-406: Reject copies to the same logical console file - #5354

Open
Hiiva wants to merge 1 commit into
ItsNotRexed:mainfrom
Hiiva:fix/console-self-copy
Open

Hiiva wants to merge 1 commit into
ItsNotRexed:mainfrom
Hiiva:fix/console-self-copy

Conversation

@Hiiva

@Hiiva Hiiva commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Copying a package-only console file to its own logical name succeeds because the source and overlay destination are different host files. The title gets a false success and an unwanted overlay. Native Windows rejects the self-copy. A locked self-copy with FAIL_IF_EXISTS also reports the wrong error.

Change

RT-406 adds a shared guard before any destination preparation or writable-source copy-up. It compares normalized console components using the existing parser and case comparison, then probes the visible source read-only to preserve native source-error precedence. All five CopyFile routes reject equal logical names without creating an overlay file or parent. Existing overlay contents stay intact, and distinct/host copies retain their behavior.

The scope is equal logical console paths, including GAME:/G: aliases, case, separators, and dot/parent normalization. It does not add general failed-copy rollback or physical hard-link detection. CopyFile2 early errors retain the existing policy of returning an HRESULT without synthesizing progress error messages; native Windows may issue such a message.

Depends on: #5234
Depends on: #5187

The original integration used upstream 3faac557 and combined dependencies separately at exact heads 29dc0a03, 97278af44, and cc48f055. #5234 has shared code/test/doc hunks; #5187 has a test insertion conflict. Resolutions preserve both changes and place the guard before source copy-up.

Current upstream validation

Rebased onto 1cc6e3c121969761d9dad8fdec99f19928213973 at f1a79cec1beb2ce2a083641f8c8de9003f4b5e7f. The production and documentation delta is unchanged from the preceding published head. The test rebase preserves main's DACL restoration, native case-rename probe, exception boundary and cleanup, and runs the self-copy checks inside that boundary. Main's CopyFile2 cancellation check is retained.

On Windows 11 x64 with MSVC 19.44.35228 and Windows SDK 10.0.26100.0:

  • Standalone file_system CTest: 1,914 checks, zero failures.
  • Separate combination with exact RT-392: Copy writable console sources into the overlay #5234 8651615eedf0e154539ea2977a682f6ee766dc06 and RT-389: Support console current directories and relative file paths #5187 e43ed3e1e29bb8b5499d81c647b7821b40bbe9df: 2,167 filesystem checks, zero failures. The self-copy guard remains before writable-source preflight and copy-up.
  • The retained relative-path probe, unchanged and rebuilt against that combination, passes 64 cases and 260 checks. It covers all five copy APIs, writable flags, package and overlay sources, aliases, distinct destinations, and GAME:/T: separation.
  • Independent full source/range review, evidence identity checks, and git diff --check pass. Synthetic files only; no game data or GPU. Wine was not run.

#5234 and #5187 remain integration dependencies. Their exact tested heads are recorded above; the current refresh does not claim a new run of the historical #5548 OEM matrix.

Earlier upstream validation

The following results belong to the preceding 6178a411 head and are retained as historical evidence.

Rebased onto 561b65a832218fbb9e6d2effd392a8eef093a3f8 at 6178a411b5bd49e6eb4011e160fb7a55e6dc38b9. The logical self-copy guard now uses upstream's equivalent component-wise same_entry helper. Source-error precedence, logical aliases, package/overlay preservation, host behavior and the early-error callback limitation are unchanged. The now-merged #3655 parameter/fallback checks are retained.

Standalone file_system CTest: 1,740 checks, zero failures. The separate integration with refreshed #5187 (e43ed3e1), #5234 (8651615e) and unchanged #5548 (d4fbd45c) retains the self-copy guard before writable-source preflight/copy-up. All 1,993 filesystem checks, 557 OEM checks, 63 native/63 mapped directory checks, 67 encoding/path integration checks and 64 relative self-copy cases (260 checks) pass.

Documentation links, text encoding and diff checks pass. Root source/range review is clear. #5187 and #5234 remain integration dependencies; #3655 is now in main. This remains native Windows coverage; Wine was not run.

Original validation

Windows 11 x64, MSVC 19.44.35228, SDK 10.0.26100.0. Original synthetic files only; no game data or GPU work.

  • Native/shim matrix: 384 cases, 96 result mismatches and 32 unwanted overlays before; zero mismatches and zero unwanted overlays after. All five actual native APIs, ordinary/read-only/locked/missing/directory/deleted sources, valid flags, aliases, and existing overlays.
  • Production registry regression: 1,639 checks, 248 failures with unchanged main production, zero failures fixed. CTest file_system passes 1/1.
  • Exact RT-392: Copy writable console sources into the overlay #5234 plus RT-389: Support console current directories and relative file paths #5187 integration: 2,149 checks pass, including 64 relative-CWD self-copy/positive-copy cases and scratch-drive separation controls.
  • With exact file_system: CopyFile2 falls back to CopyFileExW on Wine 9 (RT-237) #3655: 2,178 checks pass, including forced fallback parameter precedence, self-copy errors, and successful writable-source copy-up. This is Windows fallback coverage, not a Wine run.
  • Docs link tests 6/6, encoding tests 2/2, and git diff --check pass. Independent source review found no actionable issue.

Coordination: #5256 (comment)

AI-assisted: yes.

@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.

Reviewed 9c34326 (MSVC 19.44.35228, Ninja, RelWithDebInfo, Windows 11).

  • Built file_system_test from runtime/ and ran it -> 1639 check(s), 0 failure(s), exit 0. CTest -R file_system passes 1/1.
  • Negative control: with runtime/shims/file_system.cpp restored to origin/main, the same binary -> 1639 check(s), 248 failure(s), exit 1, so the new cases do exercise the guard (matches the PR's number). Source restored afterwards.
  • check_self_copies compares the shim's result and error against the real CopyFileW/A, CopyFileExW/A and CopyFile2 over 8 source states x 4 flag sets x overlay/no-overlay x alias/exact name, and checks package/overlay bytes, no overlay parent, no progress callbacks, plus the host self-copy path.
  • python -I -m pytest tests/test_docs_links.py -q -> 6 passed; tests/test_text_encoding.py -> 2 passed.
  • git diff --check clean.

Merge order depends on #5234, #5187 and #3655 as stated; the guard itself applies and passes standalone at 3faac557 + this commit.

Verdict: OK to merge once the dependencies land.

@memorypressure

Copy link
Copy Markdown

Review-only check against main 3faac55: the C++ test needs cmake/Windows and was not built here. The guard logic reads right — it fires only for two pure-console logical paths so host self-copies keep native behavior, it sits after source-open errors with the documented precedence (FIE, then read-only, then sharing), the test target is already registered in runtime/CMakeLists.txt, and docs/runtime_imports.md was updated to match. Python-side guards pass: test_exe_checklist, test_docs_repo_paths, test_docs_list_items all OK. The branch reports no CI checks — the windows job is the real check for this one and it is not running. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only review).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 9c34326 on Intel UHD Graphics 770, driver 32.0.101.7088: file_system_test.exe exits 0 with "1639 check(s), 0 failure(s)" and ctest -R file_system passes. The log has "PASS CopyFileW self-copy: ordinary, flags=0, overlay=0, alias=1", "PASS self-copy rejected before copying sends no progress callback" and "PASS self-copy read-only fixture". The 384-case native and shim matrix, the run on main, and a build combined with the PRs this one depends on were not run.

AI-assisted.

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 561b65a832218fbb9e6d2effd392a8eef093a3f8 at 6178a411b5bd49e6eb4011e160fb7a55e6dc38b9. The logical self-copy guard now uses upstream's equivalent component-wise same_entry helper. Source-error precedence, logical aliases, package/overlay preservation, host behavior and the early-error callback limitation are unchanged. The now-merged #3655 parameter/fallback checks are retained.

Standalone file_system CTest: 1,740 checks, zero failures. The separate integration with refreshed #5187 (e43ed3e1), #5234 (8651615e) and unchanged #5548 (d4fbd45c) retains the self-copy guard before writable-source preflight/copy-up. All 1,993 filesystem checks, 557 OEM checks, 63 native/63 mapped directory checks, 67 encoding/path integration checks and 64 relative self-copy cases (260 checks) pass.

Documentation links, text encoding and diff checks pass. Root source/range review is clear. #5187 and #5234 remain integration dependencies; #3655 is now in main. This remains native Windows coverage; Wine was not run.

All fixtures and overlays are synthetic. No game files accessed or GPU used. AI-assisted: yes.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 6178a41 on NVIDIA GeForce RTX 4080, driver 617.42: file_system_test exits 0 with "1738 check(s), 0 failure(s)". The log has "PASS self-copy rejected before copying sends no progress callback", "PASS CopyFile2 self-copy: deleted, flags=5, overlay=0, alias=1", "PASS a distinct destination still copies the visible source into the overlay" and "PASS a host self-copy preserves native errors, callbacks, and bytes". The description's standalone count is 1,740.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 6178a41 merged with main 561b65a on Windows (native, MSVC 14.51 / VS 18, Ninja, RelWithDebInfo, built from a git archive copy of the merge; file_system_test target only) and Linux (WSL2) / Python 3.12.16 for the docs tests: pass

file_system_test.exe: 1740 checks, 0 failures, including the new self-copy matrix (CopyFileW/A, CopyFileExW/A and CopyFile2, ordinary / read-only / locked / missing / directory / deleted sources, package and overlay, with and without the G: alias, and the no-progress-callback check). All 11 tests/test_docs_*.py pass on Linux (docs edit in docs/runtime_imports.md).

Negative control: runtime/shims/file_system.cpp taken from upstream/main, rebuilt, same test: 1740 checks, 248 failures, exit code 1. Not run: the rest of the runtime test suite, Wine, a GPU.

@larpinguser larpinguser left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary: runtime/shims/file_system.cpp adds same_console_path and self_copy_error so copy APIs reject equal logical console paths (aliases, case, ./..) before creating overlays or parents, with source-open, fail-if-exists, read-only, then sharing error precedence. Tests exercise CopyFileW/A/ExW/ExA/CopyFile2 states and flags; docs record the behavior.

Why merge: It prevents self-copies from mutating package or overlay state and preserves native-style diagnostics.

Verdict: Approve

@larpinguser

Copy link
Copy Markdown

Summary: runtime/shims/file_system.cpp adds same_console_path and self_copy_error so copy APIs reject equal logical console paths (aliases, case, ./..) before creating overlays or parents, with source-open, fail-if-exists, read-only, then sharing error precedence. Tests exercise CopyFileW/A/ExW/ExA/CopyFile2 states and flags; docs record the behavior.

Why merge: It prevents self-copies from mutating package or overlay state and preserves native-style diagnostics.

Verdict: Approve

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed onto main 1cc6e3c121969761d9dad8fdec99f19928213973 at f1a79cec1beb2ce2a083641f8c8de9003f4b5e7f. Production and documentation are unchanged from the prior patch; the test merge preserves main's DACL/case-probe helpers and exception cleanup.

Current native Windows results: 1,914 standalone filesystem checks; 2,167 in the separate exact #5234 8651615e + #5187 e43ed3e1 combination; 64 retained relative-copy cases with 260 checks. All pass. The logical self-copy guard stays before writable-source copy-up, and main's CopyFile2 cancellation handling is retained. Independent source and evidence review is clear. The PR body separates these results from historical OEM and earlier-base runs.

Synthetic data only, no game files or GPU. AI-assisted: yes.

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.

6 participants