WIP: fix(sandbox): Windows: a confined game reads a profile past 260 characters: the file layer takes the extended-length prefix #2838

Draft
llun wants to merge 3 commits from llun/Longshot:fix/mod-api-win-long-paths into mod-api
Member

Summary

For #2822 (into mod-api). On Windows, a confined game whose profile's path passes 260 characters reads nothing of the profile from its Rust side. It logs:

  • the settings file …\settings\settings.toml could not be read (Access is denied. (os error 5)): every setting at its default, and nothing saved this run
  • profile.json is not a list of mods (Access is denied …)
  • a development mod's folder with no mod in it

The C side reads the same profile fine.

The game reaches the player's files through its file layer, host/hos_file_windows.c, which hands an open to the builder only when whole_utf8 finds a drive's (C:\…) or a share's (\\server\…) path. Rust's std gives a path past MAX_PATH Windows' extended-length prefix (\\?\C:\…), and GetFullPathNameW leaves that form as it is. So those opens stayed native calls, which the AppContainer refuses. whole_utf8 now also takes \\?\C:\… and \\?\UNC\server\share\…, and hands them on in their plain form, which the builder's rules take (files_rules). A device's path (\\.\…, \\?\Volume{…}), a pipe and the console are still never the builder's.

To see it on mod-api: Windows, a profile at a path longer than 260 characters, longshot-builder game (confined). The log has the warnings above, and the profile's mods don't start.

Read first: whole_utf8 in host/hos_file_windows.c.

Testing

Tested: Windows 11, RTX 5080, NVIDIA 621.40, confined through longshot-builder game, with a profile copied to a folder 285 characters deep (given as a plain C:\… path), holding three script mods and a development mod.

  • Before: the three warnings above, and none of the profile's mods started.
  • After: options: the settings file is …\settings\settings.toml, the profile's three mods started, and the development mod was found (it waits for its permission prompt, as with a short path). No access-denied line.

Both runs are on mod-api with #2726's save-folder fix and its broker change applied locally, beneath this PR. On plain mod-api a confined Windows start with a profile stops at the save folder. A profile path with spaces and non-ASCII letters (modapi run é ü) was also run, and it works the same before and after.

Checks:

  • The new tests/test_file_layer_long_paths.py (Windows; skipped on Linux) cuts whole_utf8 from the source, compiles it with the PC's clang and gives it each path form. It fails on mod-api @ eaf4a48b (the two prefixed forms "never the builder's") and passes here.
  • tests/test_sandbox_windows.py and tests/test_builder_files_wine.py pass (the latter needs Wine, which this PC lacks, so it was skipped here).
  • The whole host/hos_file_windows.c compiles with -Wall -Wextra -Werror (llvm-mingw clang) before and after.
  • The new build-core test files_rules::tests::the_extended_length_form_keeps_every_refusal checks the builder's rules on what the layer now hands them. Every name Windows reads differently under \\?\ stays refused in that form: .., ., a trailing dot or space, a stream's :, a device's name, *. So does a \\?\ path that is not a drive's or a share's: a volume's, GLOBALROOT, a pipe. It passes on mod-api and here, on Windows and Linux (it pins what the change relies on).
  • mise run lint passes.

Still to test:

  • Windows: a launcher profile in a deep folder (past 260 characters), played from the launcher, expecting its settings and mods to load (by hand)

Measurements

Verdict: fixed. A confined Windows game reads a profile past 260 characters.

Baseline: mod-api (#2822's head), the branch this PR goes into: the bug is there, not on main. The in-game runs are both on mod-api with #2726's save-folder fix and broker change applied locally, beneath this PR.

Setup: Windows 11, RTX 5080, NVIDIA 621.40, the game confined, the same 285-character profile. The log's lines, and the check.

Before: mod-api @ eaf4a48b After: this PR @ 56668d15
settings.toml "could not be read (Access is denied. (os error 5))" read
profile.json's list "is not a list of mods (Access is denied …)" read; its 3 mods started
The development mod's folder "with no mod in it" found
tests/test_file_layer_long_paths.py FAIL pass

Risks

Only the file layer's choice of what the builder serves changes: opens with the prefix now reach the builder's rules, which decide as for the plain path.

The sandbox keeps every guarantee. The builder decides each such open by its own rules (files_rules::norm, decide), which already took the \\?\ form and strip it before checking. The names that mean something else under the prefix are refused in either form (the test above), and the builder still checks an opened file's final path under its root and refuses links. No grant, root or right changes: a file outside the player's roots is refused as before, now by the builder instead of by Windows. A revert is enough. Players on Windows with a profile in a deep folder get their settings and mods.

Checklist

Ready for review

  • One topic, on current mod-api (#2822's head); the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (The checks this change reaches pass. mod-api's whole suite has failures on Windows that this PR doesn't change.)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here. (It fails on mod-api, where the bug is.)
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows built and run; the file is Windows' alone; Linux: CI.)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary For [#2822](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2822) (into `mod-api`). On Windows, a confined game whose profile's path passes 260 characters reads nothing of the profile from its Rust side. It logs: - `the settings file …\settings\settings.toml could not be read (Access is denied. (os error 5)): every setting at its default, and nothing saved this run` - `profile.json is not a list of mods (Access is denied …)` - a development mod's folder `with no mod in it` The C side reads the same profile fine. The game reaches the player's files through its file layer, `host/hos_file_windows.c`, which hands an open to the builder only when `whole_utf8` finds a drive's (`C:\…`) or a share's (`\\server\…`) path. Rust's std gives a path past `MAX_PATH` Windows' extended-length prefix (`\\?\C:\…`), and `GetFullPathNameW` leaves that form as it is. So those opens stayed native calls, which the AppContainer refuses. `whole_utf8` now also takes `\\?\C:\…` and `\\?\UNC\server\share\…`, and hands them on in their plain form, which the builder's rules take (`files_rules`). A device's path (`\\.\…`, `\\?\Volume{…}`), a pipe and the console are still never the builder's. **To see it on `mod-api`:** Windows, a profile at a path longer than 260 characters, `longshot-builder game` (confined). The log has the warnings above, and the profile's mods don't start. Read first: `whole_utf8` in `host/hos_file_windows.c`. ## Testing **Tested:** Windows 11, RTX 5080, NVIDIA 621.40, confined through `longshot-builder game`, with a profile copied to a folder 285 characters deep (given as a plain `C:\…` path), holding three script mods and a development mod. - Before: the three warnings above, and none of the profile's mods started. - After: `options: the settings file is …\settings\settings.toml`, the profile's three mods started, and the development mod was found (it waits for its permission prompt, as with a short path). No access-denied line. Both runs are on `mod-api` with [#2726](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2726)'s save-folder fix and its broker change applied locally, beneath this PR. On plain `mod-api` a confined Windows start with a profile stops at the save folder. A profile path with spaces and non-ASCII letters (`modapi run é ü`) was also run, and it works the same before and after. Checks: - The new `tests/test_file_layer_long_paths.py` (Windows; skipped on Linux) cuts `whole_utf8` from the source, compiles it with the PC's clang and gives it each path form. It fails on `mod-api` @ eaf4a48b (the two prefixed forms "never the builder's") and passes here. - `tests/test_sandbox_windows.py` and `tests/test_builder_files_wine.py` pass (the latter needs Wine, which this PC lacks, so it was skipped here). - The whole `host/hos_file_windows.c` compiles with `-Wall -Wextra -Werror` (llvm-mingw clang) before and after. - The new `build-core` test `files_rules::tests::the_extended_length_form_keeps_every_refusal` checks the builder's rules on what the layer now hands them. Every name Windows reads differently under `\\?\` stays refused in that form: `..`, `.`, a trailing dot or space, a stream's `:`, a device's name, `*`. So does a `\\?\` path that is not a drive's or a share's: a volume's, `GLOBALROOT`, a pipe. It passes on `mod-api` and here, on Windows and Linux (it pins what the change relies on). - `mise run lint` passes. **Still to test:** - Windows: a launcher profile in a deep folder (past 260 characters), played from the launcher, expecting its settings and mods to load (by hand) ## Measurements **Verdict:** fixed. A confined Windows game reads a profile past 260 characters. Baseline: `mod-api` (#2822's head), the branch this PR goes into: the bug is there, not on `main`. The in-game runs are both on `mod-api` with #2726's save-folder fix and broker change applied locally, beneath this PR. Setup: Windows 11, RTX 5080, NVIDIA 621.40, the game confined, the same 285-character profile. The log's lines, and the check. | | Before: mod-api @ eaf4a48b | After: this PR @ 56668d15 | |---|---|---| | `settings.toml` | "could not be read (Access is denied. (os error 5))" | read | | `profile.json`'s list | "is not a list of mods (Access is denied …)" | read; its 3 mods started | | The development mod's folder | "with no mod in it" | found | | `tests/test_file_layer_long_paths.py` | FAIL | pass | ## Risks Only the file layer's choice of what the builder serves changes: opens with the prefix now reach the builder's rules, which decide as for the plain path. The sandbox keeps every guarantee. The builder decides each such open by its own rules (`files_rules::norm`, `decide`), which already took the `\\?\` form and strip it before checking. The names that mean something else under the prefix are refused in either form (the test above), and the builder still checks an opened file's final path under its root and refuses links. No grant, root or right changes: a file outside the player's roots is refused as before, now by the builder instead of by Windows. A revert is enough. Players on Windows with a profile in a deep folder get their settings and mods. ## Checklist ### Ready for review - [x] One topic, on current `mod-api` (#2822's head); the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). (The checks this change reaches pass. `mod-api`'s whole suite has failures on Windows that this PR doesn't change.) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. (It fails on `mod-api`, where the bug is.) - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows built and run; the file is Windows' alone; Linux: CI.) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
host/hos_file_windows.c's whole_utf8 cut and compiled with the PC's C compiler, given each path form: \?\C:\... and
\?\UNC\server\share\... must be the builder's, in their plain form, as C:\... and \server\... are; a device's path, a
pipe and the console never. It fails on mod-api: the prefixed forms are never the builder's, so in a profile past 260
characters the confined game's Rust read nothing of it ("settings.toml could not be read (Access is denied. (os
error 5))", "profile.json is not a list of mods (Access is denied ...)"). Windows only (RUN_ALL_SKIP on Linux).

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(sandbox): Windows: a confined game reads a profile past 260 characters: the file layer takes the extended-length prefix
All checks were successful
PR description / Title and description (pull_request_target) Successful in 9s
e902b8c595
host/hos_file_windows.c hands the builder only a drive's or a share's path, and GetFullPathNameW leaves a path with
Windows' extended-length prefix as it is. Rust's std gives a path past MAX_PATH that prefix (\?\C:\...), so in a
profile that long every file the game's Rust opens, lists or reads there stayed a native call the AppContainer refuses:
settings.toml "could not be read (Access is denied. (os error 5)): every setting at its default", profile.json "is not
a list of mods", a development mod's folder empty. whole_utf8 now takes \?\C:\... and \?\UNC\server\share\... too,
and hands them on in their plain form, which the builder's rules take; a device's path stays never the builder's.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in the game: Windows 11, RTX 5080, NVIDIA 621.40, confined through longshot-builder game with a profile copied to a folder 285 characters deep (on mod-api with #2726's save-folder fix and its broker change applied locally, beneath this PR). Before: settings.toml could not be read (Access is denied. (os error 5)), profile.json is not a list of mods (Access is denied ...), the development mod's folder with no mod in it, no profile mod started. After: the settings file read, the profile's 3 mods started, the development mod found; no access-denied line.

Tested in the game: Windows 11, RTX 5080, NVIDIA 621.40, confined through `longshot-builder game` with a profile copied to a folder 285 characters deep (on mod-api with #2726's save-folder fix and its broker change applied locally, beneath this PR). Before: `settings.toml could not be read (Access is denied. (os error 5))`, `profile.json is not a list of mods (Access is denied ...)`, the development mod's folder `with no mod in it`, no profile mod started. After: the settings file read, the profile's 3 mods started, the development mod found; no access-denied line.
Member

Possibly related, for context:

  • PR #2747 WIP: fix(sandbox): the test mode's start reads its folder in the container after the broker's file layer is in — Nearby sandbox file-layer work on mod-api; distinct test-mode startup issue
Possibly related, for context: - PR #2747 WIP: fix(sandbox): the test mode's start reads its folder in the container after the broker's file layer is in — Nearby sandbox file-layer work on mod-api; distinct test-mode startup issue
test(sandbox): the builder's file rules keep every refusal for a path in Windows' extended-length form
All checks were successful
PR description / Title and description (pull_request_target) Successful in 8s
1e81039087
The file layer now hands the builder a path with the \?\ prefix (in its plain form). Under the prefix Windows takes a
name as it is: `..`, a trailing dot or space and `:` are names there. files_rules::norm must refuse each of those in that
form as it does in the plain one (it strips the prefix and checks the rest: path_norm), never take the plain path's
meaning, and a \?\ path that is not a drive's or a share's (a volume's, GLOBALROOT, a pipe) is none of the service's.
It passes on mod-api: the change keeps the sandbox's refusals; this pins them.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Pushed a refusal test (1e810390): the builder's file rules refuse, in the ?\ form too, every name Windows reads differently under that prefix (.., ., a trailing dot or space, a stream, a device's name), and a ?\ path that is not a drive's or a share's. It passes on mod-api and here, on Windows and Linux. Risks now says how the change keeps the sandbox's guarantees.

Pushed a refusal test (1e810390): the builder's file rules refuse, in the \?\ form too, every name Windows reads differently under that prefix (.., ., a trailing dot or space, a stream, a device's name), and a \?\ path that is not a drive's or a share's. It passes on mod-api and here, on Windows and Linux. Risks now says how the change keeps the sandbox's guarantees.
llun force-pushed fix/mod-api-win-long-paths from 1e81039087
All checks were successful
PR description / Title and description (pull_request_target) Successful in 8s
to 7d780aeebc
All checks were successful
PR description / Title and description (pull_request_target) Successful in 13s
2026-11-29 23:27:57 +00:00
Compare
Author
Member

Rebased onto mod-api's newest (4cc50ca1: main's newest merged in), with no conflict; this PR's own checks were run again on the rebased head and pass as before. The merge touched none of this PR's files (#2827: only a comment in host/hos_main.c, far from its change), so the measurements and runs above hold; the After commit is the rebased head.

Rebased onto mod-api's newest (4cc50ca1: main's newest merged in), with no conflict; this PR's own checks were run again on the rebased head and pass as before. The merge touched none of this PR's files (#2827: only a comment in host/hos_main.c, far from its change), so the measurements and runs above hold; the After commit is the rebased head.
llun force-pushed fix/mod-api-win-long-paths from 7d780aeebc
All checks were successful
PR description / Title and description (pull_request_target) Successful in 13s
to fd685a47fd
All checks were successful
PR description / Title and description (pull_request_target) Successful in 7s
2026-11-29 23:58:28 +00:00
Compare
Author
Member

Rebased onto mod-api @ 816d2354 (#2837, headless shots of the mods' UI), now fd685a47. No conflict, and the diff is the same as before (same git patch-id). #2837 touches none of this PR's files.

Rebased onto `mod-api` @ 816d2354 ([#2837](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2837), headless shots of the mods' UI), now fd685a47. No conflict, and the diff is the same as before (same `git patch-id`). #2837 touches none of this PR's files.
llun force-pushed fix/mod-api-win-long-paths from fd685a47fd
All checks were successful
PR description / Title and description (pull_request_target) Successful in 7s
to 4c9fe20520
All checks were successful
PR description / Title and description (pull_request_target) Successful in 1m45s
2026-11-30 00:38:50 +00:00
Compare
llun force-pushed fix/mod-api-win-long-paths from 4c9fe20520
All checks were successful
PR description / Title and description (pull_request_target) Successful in 1m45s
to 56668d15e4
All checks were successful
PR description / Title and description (pull_request_target) Successful in 15s
2026-11-30 00:43:22 +00:00
Compare
Author
Member

Rebased onto mod-api @ c5e5b676: it was re-squashed onto main @ 46291934 (#2833) twice today (cdbb8551, then c5e5b676), which made this PR show main's and the whole mod API's diff. Now 56668d15, the same diff as before (same git patch-id), no conflict. The changes underneath touch none of this PR's files, so its checks still hold.

Rebased onto `mod-api` @ c5e5b676: it was re-squashed onto main @ 46291934 (#2833) twice today (cdbb8551, then c5e5b676), which made this PR show main's and the whole mod API's diff. Now 56668d15, the same diff as before (same `git patch-id`), no conflict. The changes underneath touch none of this PR's files, so its checks still hold.
All checks were successful
PR description / Title and description (pull_request_target) Successful in 15s
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/mod-api-win-long-paths:llun-fix/mod-api-win-long-paths'
git switch 'llun-fix/mod-api-win-long-paths'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'mod-api'
git merge --no-ff 'llun-fix/mod-api-win-long-paths'
git switch 'llun-fix/mod-api-win-long-paths'
git rebase 'mod-api'
git switch 'mod-api'
git merge --ff-only 'llun-fix/mod-api-win-long-paths'
git switch 'llun-fix/mod-api-win-long-paths'
git rebase 'mod-api'
git switch 'mod-api'
git merge --no-ff 'llun-fix/mod-api-win-long-paths'
git switch 'mod-api'
git merge --squash 'llun-fix/mod-api-win-long-paths'
git switch 'mod-api'
git merge --ff-only 'llun-fix/mod-api-win-long-paths'
git switch 'mod-api'
git merge 'llun-fix/mod-api-win-long-paths'
git push origin 'mod-api'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2838
No description provided.