Skip to content

RT-392: Copy writable console sources into the overlay - #5234

Open
Hiiva wants to merge 2 commits into
ItsNotRexed:mainfrom
Hiiva:fix/copy-writable-source
Open

Hiiva wants to merge 2 commits into
ItsNotRexed:mainfrom
Hiiva:fix/copy-writable-source

Conversation

@Hiiva

@Hiiva Hiiva commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

COPY_FILE_OPEN_SOURCE_FOR_WRITE gives a copy progress callback a writable source handle. The console-path shims currently resolve that source with read_target(), so a callback can modify the package directly when no source overlay exists.

Change

Pass the complete copy flags through copy_paths(). For a writable console source, check source readability with a read-only open and validate the destination without creating overlay directories. Then use the existing write_target(from, true) copy-up path before calling the host API. This covers CopyFileExW, CopyFileExA, and CopyFile2 while preserving native source-error precedence. Host sources keep their native write behavior.

The regression uses actual aligned, overlapped WriteFile calls through the source handles received by progress callbacks. It checks full source and destination contents for ordinary copies, writable copies, preexisting overlays, explicit host sources, and deleted sources.

Current upstream validation

Refreshed onto main 1cc6e3c121969761d9dad8fdec99f19928213973 at 2fdf48472b1a3f4d8a109731486a0c9a0f01981f. The two commits preserve their production behavior. The conflict resolution retains main's CopyFile2 cancellation check, read-only package deletion behavior, DACL restoration and exception-safe test cleanup. The range diff contains only surrounding upstream context changes.

Fresh Windows 11 x64 / MSVC 19.44.35228 / Windows SDK 10.0.26100.0 build and filesystem CTest: 671 checks, zero failures, including nine source-callback variants, 38 native preflight comparisons, both pre-set cancellation controls and the DACL restoration check. Documentation links, text encoding and diff checks pass. Independent root source, range and evidence review is clear.

This run validates the standalone current-main branch. The earlier combined filesystem, OEM and relative-path measurements below belong to their recorded older heads. Refreshed current-directory and self-copy integration will be reported separately. No Wine or GPU run; synthetic files only.

Maintenance status: #6603 (comment)

Earlier upstream validation

The following results belong to the preceding 8651615e head.

Rebased onto 561b65a832218fbb9e6d2effd392a8eef093a3f8 at 8651615eedf0e154539ea2977a682f6ee766dc06. The now-merged #3655 parameter-block and unsupported-fallback checks remain before any copy-up or destination preparation. Writable-source handling, read-only source preflight, and the documented later-failure rollback limit are unchanged.

Standalone file_system CTest: 497 checks, zero failures, including actual callback WriteFile controls and all merged upstream filesystem checks. Combined with refreshed #5187/#5354 and unchanged #5548, 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. #3655 is no longer an unresolved dependency. This remains native Windows coverage; Wine was not run.

Initial validation

  • Base: upstream 3faac557b1584d39004357918e60325b4d4ff0fe.
  • Windows 11 x64, MSVC 19.44.35228, Windows SDK 10.0.26100.0.
  • New tests against unchanged production: 223 checks, exactly 6 failures. Each of the three APIs modified the package and failed to create the source overlay.
  • Fixed branch: all 223 checks pass; file_system CTest passes.
  • Exact file_system: CopyFile2 falls back to CopyFileExW on Wine 9 (RT-237) #3655 integration at cc48f055ff234813fe91b6ecbb44991c11394e39: 248 checks pass, including four additional validation/fallback controls. Malformed or unsupported CopyFile2 parameters fail before copy-up; forced fallback creates the source overlay and retains its no-callback behavior.
  • Local integration with RT-389: Support console current directories and relative file paths #5187 and the other completed fixes: file_system and run_tiny_current_directory both pass.
  • Documentation links: 6 passed. Text encoding: 2 passed. git diff --check passes.
  • Independent source review completed.
cmake --build runtime/build --config RelWithDebInfo --target file_system_test --parallel 4
ctest --test-dir runtime/build -C RelWithDebInfo -R "^file_system$" --output-on-failure
python -I tests/test_docs_links.py
python -I tests/test_text_encoding.py

Rejected-destination review follow-up

Commit 29dc0a03c2740e6b08ee3ca4b327411c553505ee addresses the review finding. A destination rejected during preflight leaves the source overlay unchanged, including an existing host destination with FAIL_IF_EXISTS. Missing, directory, deleted, and exclusively held sources retain their native error precedence; a readable shared writer does not cause a false sharing violation.

  • The new regression against the original PR production source gives 396 checks with 32 failures: 20 unexpected source overlays and 12 source-error mismatches. The follow-up passes all 396 checks and the file_system CTest.
  • Thirty-eight source/destination cases compare actual native CopyFileExW or CopyFile2 results. Successful retries remove the destination conflict and perform real callback source writes, preserving package and destination contents.
  • Exact file_system: CopyFile2 falls back to CopyFileExW on Wine 9 (RT-237) #3655 integration at cc48f055ff234813fe91b6ecbb44991c11394e39: 425 checks pass, retaining parameter validation and the forced-fallback contract. This is a Windows fallback check; Wine was not run.
  • The combined tree with RT-389: Support console current directories and relative file paths #5187 and our other fixes rebuilds file_system_test, gta6rt, and tiny_current_directory; both file_system and run_tiny_current_directory CTests pass.
  • Documentation links: 6 passed. Text encoding: 2 passed. Diff check passes. Independent source review found no actionable issue.

The guarantee covers preflight rejection. A later host-copy failure does not roll back a source already copied up. Self-copy identity and general CopyFile2 preflight-error callbacks are outside this follow-up.

Integration

#3655 is now part of upstream 561b65a. The rebase retains its parameter validation and host/fallback dispatch while passing the full flags to copy_paths(). Its CopyFileW staging change also avoids the missing host CopyFile2 import during copy-up on Wine 9. The combined behavior was tested on Windows; Wine was not run here.

No import-registration or ABI change. GPU not exercised. All inputs were synthetic; no game files were accessed.

Claim: #5156 (comment)

AI-assisted: yes.

@editrice

Copy link
Copy Markdown

On exact head 963ec01, a writable copy that fails because its destination already exists still copies the package source into the overlay. copy_paths() calls write_target(from, true) before copy_destination(), so COPY_FILE_OPEN_SOURCE_FOR_WRITE | COPY_FILE_FAIL_IF_EXISTS leaves a new source overlay even though CopyFileExW, CopyFileExA, and CopyFile2 correctly fail and never invoke the callback. A synthetic case reproduced this for all three APIs (3 failures in 226 checks). Validating the destination before source copy-up made the augmented file_system suite pass 226/226 on Windows 11 / MSVC 19.44. Please preflight the destination before mutating the source overlay, while preserving source-error behavior. AI-assisted; synthetic only, no game files.

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

Review: PR #5234 @ 963ec01 (base 3faac55; Windows 11, MSVC 19.44, Ninja, RelWithDebInfo)

Configured C:/Users/kam/AppData/Local/Temp/opencode/review-5234/runtime/build-5234 (VULKAN_SDK=1.4.363.0, LEONIDA_VK_DEVICE="RTX 5070 Ti"):

cmake -S C:/Users/kam/AppData/Local/Temp/opencode/review-5234/runtime -B C:/Users/kam/AppData/Local/Temp/opencode/review-5234/runtime/build-5234 -G Ninja -DCMAKE_MAKE_PROGRAM="C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DVulkan_INCLUDE_DIR=C:/VulkanSDK/1.4.363.0/Include -DVulkan_LIBRARY=C:/VulkanSDK/1.4.363.0/Lib/vulkan-1.lib -DVulkan_GLSLANG_VALIDATOR_EXECUTABLE=C:/VulkanSDK/1.4.363.0/Bin/glslangValidator.exe

Build: cmake --build <build-5234> --target file_system_test -> exit 0.
Run: .\file_system_test.exe from the build dir -> exit 0, 223 check(s), 0 failure(s).
New coverage executed: all 9 copy source case variants (CopyFileExW / CopyFileExA / CopyFile2 x 3), including "callback source writes require COPY_FILE_OPEN_SOURCE_FOR_WRITE", "copy callback never changes package bytes", "writable-copy source does not resurrect a deleted package file" - all PASS.
ctest -R file_system -> 1/1 passed (0.86 s), exit 0.
git diff --check -> clean, exit 0.

Verdict: no blocking issue. Copy-up before the writable source handle is opened is correct and covered. Caveat: the Wine no-host-CopyFile2 fallback is unreachable on this machine (host CopyFile2 present), so that branch rests on inspection.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 963ec01 on NVIDIA GeForce RTX 4080, driver 617.42: file_system_test exits 0 with "223 check(s), 0 failure(s)", including "PASS CreateFile2 creates a new GAME: file in the overlay", "PASS copy-up leaves no staging file behind" and "PASS T:.. cannot climb out of the scratch folder into the package". The new copy-callback checks print no line of their own, so this run shows the suite passing at this head but does not show those cases by name, and I did not run the code without the change.

AI-assisted.

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the rejected-destination copy-up finding in 29dc0a03c2740e6b08ee3ca4b327411c553505ee.

Writable console sources now get a read-only readability check first, followed by destination validation that creates no overlay directories. Source copy-up happens only after those checks pass. This preserves native precedence for missing, directory, deleted, and exclusively held sources, while a readable shared writer does not cause a false sharing violation. Existing package, overlay, and host destinations with FAIL_IF_EXISTS leave the source overlay unchanged.

Windows 11 x64 / MSVC 19.44.35228 / SDK 10.0.26100:

  • New tests against published 963ec01a: 396 checks, 32 failures (20 unexpected overlays and 12 source-error mismatches).
  • Follow-up: 396 checks, zero failures; file_system CTest passes. Cases use actual native error oracles and retry successful writable copies through real callbacks after removing the conflict.
  • Exact file_system: CopyFile2 falls back to CopyFileExW on Wine 9 (RT-237) #3655 at cc48f055: 425 checks, zero failures, retaining parameter validation and forced-fallback behavior. Windows fallback only; Wine was not run.
  • Integration with RT-389: Support console current directories and relative file paths #5187 and our other fixes rebuilds the actual runtime and passes the filesystem/current-directory CTests.
  • Documentation links 6/6, text encoding 2/2, diff check clean, and independent source review clear.

The documented guarantee covers preflight rejection. Later host-copy failures do not roll back a source already copied up. Synthetic inputs only; no game files or GPU work. AI-assisted: yes.

@Krashgamer

Copy link
Copy Markdown
Contributor

Tested 29dc0a03 (it already contains main 3faac557) on native Windows 11 Pro 26200 (NTFS), MSVC 14.51 (VS 2026 Build Tools), Ninja, RelWithDebInfo, full runtime/ build: pass. This is the first run of this head by someone other than the author.

  • file_system_test: 396 checks, 0 failures. The count is higher than the description's 223 because main added checks since. ctest -R "file_system|run_tiny|loader": 13/13 pass. No new warnings in file_system.cpp or file_system_test.cpp.
  • Negative control 1: main's runtime/shims/file_system.cpp with this PR's tests gives 21 failures. Among them are "copy callback never changes package bytes", "writable source uses the overlay; ordinary copy does not copy up its source" and the error-precedence cases.
  • Negative control 2, for editrice's finding: reverting only 29dc0a03's file_system.cpp hunk (back to 963ec01a's copy-up order) gives 32 failures, led by "failed writable copy leaves its source overlay unchanged and starts no source write". With the head's file restored, 396 / 0 again. So the follow-up is what keeps a rejected destination from copying the package source into the overlay.

Not checked: the #3655 and #5187 integrations from the description, and Wine.

AI-assisted (Claude Code). Synthetic files only.

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto 561b65a832218fbb9e6d2effd392a8eef093a3f8 at 8651615eedf0e154539ea2977a682f6ee766dc06. The now-merged #3655 parameter-block and unsupported-fallback checks remain before any copy-up or destination preparation. Writable-source handling, read-only source preflight, and the documented later-failure rollback limit are unchanged.

Standalone file_system CTest: 497 checks, zero failures, including actual callback WriteFile controls and all merged upstream filesystem checks. Combined with refreshed #5187/#5354 and unchanged #5548, 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. #3655 is no longer an unresolved dependency. 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 8651615 on NVIDIA GeForce RTX 4080, driver 617.42: file_system_test exits 0 with "495 check(s), 0 failure(s)". The description reports 497 checks. The log prints no line naming the copy-callback cases, so the total is the only evidence they ran. run_tiny_current_directory was not run.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 8651615 merged with main 561b65a on Windows 11 / MSVC 14.51 (VS 18), cmake + Ninja RelWithDebInfo, native: pass

Built only the file_system_test target (cmake -DBUILD_TESTING=ON, the Vulkan device is not part of this target) and ran runtime\build\file_system_test.exe: exit 0, 497 lines of PASS, 0 of FAIL. Negative control: with runtime/shims/file_system.cpp restored from main the new tests fail (exit 1, 476 PASS and 21 FAIL lines; the first failures are "copy callback never changes package bytes", "writable source uses the overlay; ordinary copy does not copy up its source", "successful retry writes its source overlay ..." and "failed writable copy preserves native source/destination error precedence"); PR file restored afterwards. The build gives one warning, C4456 at file_system_test.cpp:1221, a line that is already in main and not part of this diff. This is a Windows-only runtime shim, so I did not run it on Linux/Wine; the Wine 9 branch (no host CopyFile2, callback not invoked) is handled in the test by has_callback but I did not run that.

@Hiiva
Hiiva force-pushed the fix/copy-writable-source branch from 8651615 to 2fdf484 Compare November 23, 2026 14:53
@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Refreshed RT-392 onto main 1cc6e3c121969761d9dad8fdec99f19928213973 at 2fdf48472b1a3f4d8a109731486a0c9a0f01981f. The original two commits are preserved on the old published head 8651615eedf0e154539ea2977a682f6ee766dc06.

The resolution retains main's CopyFile2 cancellation guard after path preparation, its read-only package deletion checks, and its exception-safe filesystem test cleanup and retained-handle DACL restoration. The writable-source callback, destination preflight, source error precedence, and documented later-failure rollback limit are unchanged. The range diff contains only adjacent upstream context changes.

Fresh native Windows 11 / MSVC 19.44 RelWithDebInfo build and the filesystem CTest pass: 671 checks, zero failures. This includes all nine real source-callback variants, 38 native-error preflight comparisons, both pre-set cancellation controls, and the restored marker-folder DACL check. The build retains the existing local-variable shadow warning in an upstream test block. Diff checks pass.

This is standalone current-main validation. Earlier combined dependency measurements remain historical; refreshed current-directory and self-copy heads are separate work. No Wine or GPU run. All files and overlays are synthetic, with no game data or user saves accessed. 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