Repository navigation
file_system: T:\ is a drive root for file calls; move and copy hold the folder lock (RT-FS-OVERLAY-ROOT-LOCK-LONGPATH) - #2534
Conversation
…he folder lock Three fixes to the GAME:/T: overlay shim: - The T:\ root parses to its scratch folder's parts, not to an empty list, so the parts.empty() root checks in write_target, DeleteFileW, the copy destination and SetFileAttributesW let it through: a SetFileAttributesW(T:\) reached the host folder. They use drive_root(), as RemoveDirectory and MoveFileEx already do, with the error each gave for GAME:\. - MoveFileEx and the CopyFile family did not hold the destination folder's lock from the "does the folder exist" check to the host move or copy, as a write-open and CreateDirectory do, so a concurrent RemoveDirectory of that folder could still be undone. A copy with a progress routine does not hold it across the copy, because the routine is the title's code. - CreateDirectory removed a recreated folder's marker without win32_io_path(), so a marker beyond MAX_PATH could not be removed on a host without long path support, and the folder was not recreated. Found by kevincommits (ProjectLeonida#1608). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Reviewed at head Verification
Notes (non-blocking)
Approve. AI-assisted review + local MSVC verification. |
|
#2534 | head 11b63a5 (merged cleanly with main 6dfca64) | |
timbot103
left a comment
There was a problem hiding this comment.
Static code audit against PR head 11b63a53b and origin/main ec740bcc3.
runtime/shims/file_system.cpp:1547checks onlypProgressRoutine. A validCopyFile2V2 block can supply onlypProgressRoutineOld, so nativeCopyFile2can call back while the destination stripe is held. A callback that mutates that folder can attempt to reacquire the same non-recursive mutex. Please check both callback fields for V2 and add a native Windows regression for a re-entrant legacy callback. Win32 V2 parameters.runtime/shims/file_system.cpp:1311still mirrors the parent during a case-only package move before taking the new lock. If deletion hides the source andRemoveDirectoryWthen hides the parent after the move's source lookup, copy-up brings the parent back. Extend the destination lock and recheck the parent and source on that branch.
The new checks cover canonical T:\ refusals and long-folder recreation. The concurrency fixture covers create/remove. A direct marker absence assertion and move/copy removal cases would pin the other changes.
AI-assisted.
lixonik
left a comment
There was a problem hiding this comment.
Reviewed 11b63a53b and tested file_system on Windows 11.
Verification (Windows 11, MSVC 19.44, Ninja Release):
- Built
file_system_test. ctest -R '^file_system$': 1/1 passed (12.27 s).python -I scripts/check_no_game_data.py: passed.
Code audit:
- The
drive_root()guards forT:\, thewin32_io_path()marker removal, and holdingfolder_lock(parent_of(dst))acrossmove_file_ex_w/copy_file_w/copy_file_ex_ware solid. - Independently confirming both findings raised by
@timbot103before approving:runtime/shims/file_system.cpp(copy_file2):calls_backonly checksparameters->pProgressRoutine. In Windows SDK 10.0.26100.0 (winbase.h),COPYFILE2_EXTENDED_PARAMETERS_V2also carriesLPPROGRESS_ROUTINE pProgressRoutineOld(which takes precedence overpProgressRoutine), so a V2 caller setting onlypProgressRoutineOldwould execute guest callback code while holding the non-recursivefolder_lock.runtime/shims/file_system.cpp(move_file_ex_w,same_entry(src, dst)branch): the case-only rename copy-up (create_directories+CopyFileWwhen!from_view.in_overlay) still executes beforestd::lock_guard folder(folder_lock(parent_of(dst))), leaving a window against concurrentRemoveDirectoryW.
AI-assisted (Antigravity, Gemini).
Claimed in the coordination issue as: RT-FS-OVERLAY-ROOT-LOCK-LONGPATH (claim: #1608 (comment)). Found by @kevincommits, item 2 of #1608 (comment). Thanks!
What and why
Three fixes to the
GAME:/T:overlay inruntime/shims/file_system.cpp:T:\slipped past the root checks.parse_console(L"T:\\")gives the scratch folder's parts (.gta6rt-temp,<run>), not an empty list.RemoveDirectoryandMoveFileExalready usedrive_root()for that, but the write-open (write_target),DeleteFileW, the copy destination andSetFileAttributesWonly checkedparts.empty(). SoSetFileAttributesW(T:\)changed the host scratch folder's attributes, and a write-open ofT:\was not refused. All four now usedrive_root()and giveT:\the same error they giveGAME:\(ERROR_INVALID_NAME, orERROR_ACCESS_DENIEDfor attributes).CreateDirectoryholdfolder_lock(parent)from "does the folder exist" to the host call that makes the entry, so a concurrentRemoveDirectoryof that folder comes wholly before or after (the comment atg_folder_locks).MoveFileExandcopy_destination(CopyFileW,CopyFileExW,CopyFile2) did not, so the remove-then-resurrect race stayed open for them. Now:MoveFileExholds the lock from its destination checks to the host move.copy_destinationtakes it before its checks and hands it to the caller, which holds it through the host copy.CopyFileExWwithprogress,CopyFile2withpProgressRoutine) keeps the old behaviour. The routine is the title's code, and nothing that holds a folder lock may call back into the title (the same comment). A routine that touched a folder in the same lock stripe would otherwise deadlock.CreateDirectory. Recreating a removed folder deletes its marker withstd::filesystem::remove(marker(...) / kRemovedDirMarker)and nowin32_io_path(), unlike every other marker access. On a host without long path support, a marker beyondMAX_PATHcannot be removed, and the new folder is rolled back. It now goes throughwin32_io_path().Tested
file_system_test(CPU only, synthetic package and overlay folders, no game data):T:\root cases:SetFileAttributesWis refused and the host folder is not hidden;DeleteFileW, aGENERIC_WRITEopen andCopyFileWontoT:\areERROR_INVALID_NAME. Onmainall 4 fail; with the fix the whole test passes (544 checks, 0 failures).CreateDirectoryWrecreates a removed folder whose marker lies beyondMAX_PATH, and the folder is listed again. It also passes onmainon this machine, because long path support is on here (LongPathsEnabled = 1), so it does not show the bug; it keeps the path covered.RemoveDirectoryto land between the check and the host call, which a test cannot place reliably. The existing move, copy andCopyFile2cases all pass with the lock held.GPUs tested: n/a (CPU test).
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).MoveFileExa few lines above the new lock; whichever lands second needs a small merge there. No other open PR touches these lines.🤖 Generated with Claude Code