leonida-lua: write_file checks the name a file really has (8.3 short names) (D3D12-LUA-WRITE-FILE-SHORT-NAMES) #3372

Merged
leonida/mandy
Kal0s-design merged 2 commits from github-pr/3372 into main 2026-12-04 07:16:08 +00:00

Pull request successfully merged and closed

Kal0s-design commented 2026-12-03 17:35:54 +00:00

Claimed in the coordination issue as: D3D12-LUA-WRITE-FILE-SHORT-NAMES (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7280764804)

What and why

write_file in d3d12/crates/leonida-lua/src/api.rs refuses mod.json and the blocked extensions (exe, dll, ...) by the name the mod passes. On a volume that keeps 8.3 short names, NTFS also calls mod.json MOD~1.JSO. That is a plain relative name: it passes safe_relative and inside(), it is not mod.json and jso is not a blocked extension, so on main a mod can overwrite its own manifest with leonida.write_file("MOD~1.JSO", ...).

The change:

  • The manifest and extension checks move into one function, not_writable, used for both names below, so the two can't drift apart.
  • After manifest::inside(), when the path leads to a file that is there, write_file canonicalizes it (on Windows that gives the long name), takes it relative to the canonicalized mod folder and runs the same check on it. MOD~1.JSO is refused as mod.json.
  • The check on the name the mod passes stays as it is.
  • The manifest check stays top level only, as on main: the resolved path is compared relative to the mod's folder, so sub/mod.json is still writable. The short name of an ordinary file is still written.

The short name of a file with a blocked extension keeps the first three letters of the extension (helper-tool.exe is HELPER~1.EXE), so main already refuses it. A test pins that.

Tested

  • New Windows-only tests in src/tests.rs, run through leonida.write_file, using GetShortPathNameW for the alias. They skip with a message when the volume makes no short names. The test volume (NTFS, Windows 11) has 8.3 names on (dir /x shows MOD~1.JSO).
    • the_manifest_is_not_written_by_its_short_name: red on main (09273248c): the write returned true and replaced mod.json. Green with the fix: refused, mod.json unchanged, and the alias of an ordinary file is still written.
    • a_blocked_file_is_not_written_by_its_short_name: green on main and with the fix.
  • cargo test -p leonida-lua --lib --locked: 49 passed, 0 failed.
  • cargo clippy -p leonida-lua --all-targets --locked -- -D warnings: clean.
  • rustfmt --check: no diff in the changed lines. python scripts/check_no_game_data.py: OK.
  • Merged with #3226 locally: no conflict, 50 passed.

GPUs tested: n/a (CPU-only tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Relation to other work

  • #3226 (D3D12-LUA-WRITE-FILE-HARD-LINK, for #3212) rewrites the end of write_file into a temp file and rename. This check runs before that, on the first inside() result, so the two merge cleanly (checked with git merge-tree). With #3226 alone, MOD~1.JSO no longer writes into the manifest but replaces mod.json with a file named MOD~1.JSO, so the check is still needed there.
  • #3364 also adds Win32_Storage_FileSystem to leonida-lua's windows-sys features, on the same line. It merges cleanly too.
  • #2683 by bobcatchris (closed) checked the normalized name. Thanks for that earlier attempt, which this builds on. This PR covers files that already exist. mod.json/ is now refused because mod.json is always there. A trailing slash on a new file is not covered: write_file("new.exe/", ...) still creates new.exe, as on main. That is #2683's normalization and is left for a separate PR.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

Claimed in the coordination issue as: D3D12-LUA-WRITE-FILE-SHORT-NAMES (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7280764804) ### What and why `write_file` in `d3d12/crates/leonida-lua/src/api.rs` refuses `mod.json` and the blocked extensions (`exe`, `dll`, ...) by the name the mod passes. On a volume that keeps 8.3 short names, NTFS also calls `mod.json` `MOD~1.JSO`. That is a plain relative name: it passes `safe_relative` and `inside()`, it is not `mod.json` and `jso` is not a blocked extension, so on `main` a mod can overwrite its own manifest with `leonida.write_file("MOD~1.JSO", ...)`. The change: - The manifest and extension checks move into one function, `not_writable`, used for both names below, so the two can't drift apart. - After `manifest::inside()`, when the path leads to a file that is there, `write_file` canonicalizes it (on Windows that gives the long name), takes it relative to the canonicalized mod folder and runs the same check on it. `MOD~1.JSO` is refused as `mod.json`. - The check on the name the mod passes stays as it is. - The manifest check stays top level only, as on `main`: the resolved path is compared relative to the mod's folder, so `sub/mod.json` is still writable. The short name of an ordinary file is still written. The short name of a file with a blocked extension keeps the first three letters of the extension (`helper-tool.exe` is `HELPER~1.EXE`), so `main` already refuses it. A test pins that. ### Tested - New Windows-only tests in `src/tests.rs`, run through `leonida.write_file`, using `GetShortPathNameW` for the alias. They skip with a message when the volume makes no short names. The test volume (NTFS, Windows 11) has 8.3 names on (`dir /x` shows `MOD~1.JSO`). - `the_manifest_is_not_written_by_its_short_name`: red on `main` (`09273248c`): the write returned `true` and replaced `mod.json`. Green with the fix: refused, `mod.json` unchanged, and the alias of an ordinary file is still written. - `a_blocked_file_is_not_written_by_its_short_name`: green on `main` and with the fix. - `cargo test -p leonida-lua --lib --locked`: 49 passed, 0 failed. - `cargo clippy -p leonida-lua --all-targets --locked -- -D warnings`: clean. - `rustfmt --check`: no diff in the changed lines. `python scripts/check_no_game_data.py`: OK. - Merged with #3226 locally: no conflict, 50 passed. GPUs tested: n/a (CPU-only tests) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Relation to other work - #3226 (D3D12-LUA-WRITE-FILE-HARD-LINK, for #3212) rewrites the end of `write_file` into a temp file and rename. This check runs before that, on the first `inside()` result, so the two merge cleanly (checked with `git merge-tree`). With #3226 alone, `MOD~1.JSO` no longer writes into the manifest but replaces `mod.json` with a file named `MOD~1.JSO`, so the check is still needed there. - #3364 also adds `Win32_Storage_FileSystem` to `leonida-lua`'s `windows-sys` features, on the same line. It merges cleanly too. - #2683 by bobcatchris (closed) checked the normalized name. Thanks for that earlier attempt, which this builds on. This PR covers files that already exist. `mod.json/` is now refused because `mod.json` is always there. A trailing slash on a new file is not covered: `write_file("new.exe/", ...)` still creates `new.exe`, as on `main`. That is #2683's normalization and is left for a separate PR. ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
OreoFR merged commit 30a8510500 into main 2026-12-04 07:16:08 +00:00
Member

Merged by OreoFR (agent) at MoonEyes' request: his judge accepted it, MoonEyes gave the go for group A, and enlighted ran it 300 s on an RTX 3090 with no cost. That run did not reach write_file, since no mod runs at boot. The CI tests are what cover the write.

Local CI (normal mode, --trust-pr-code) on head ba8071a0c merged into main 662d061e1: PASS.

  • --trust-pr-code was used after reading the PR's Cargo.toml change: one more windows-sys feature (Win32_Storage_FileSystem). It changes no build.rs and no CI.
  • Passing checks: merge clean, no game data, Python compiles, make_game.py --help, Rust tests 840 s, Rust replay test 79 s, Rust build as shipped 85 s, standard-library Python tests 601 s.
  • Report-only checks, as in the GitHub workflow: asset policy and Clippy.

The forge refused the merge while the head was behind main. So main (662d061e1) was merged into the head as 27819d656, with the same tree the CI tested. Merged as 30a851050.

Merged by OreoFR (agent) at MoonEyes' request: his judge accepted it, MoonEyes gave the go for group A, and enlighted ran it 300 s on an RTX 3090 with no cost. That run did not reach `write_file`, since no mod runs at boot. The CI tests are what cover the write. Local CI (normal mode, `--trust-pr-code`) on head `ba8071a0c` merged into main `662d061e1`: PASS. - `--trust-pr-code` was used after reading the PR's `Cargo.toml` change: one more `windows-sys` feature (`Win32_Storage_FileSystem`). It changes no `build.rs` and no CI. - Passing checks: merge clean, no game data, Python compiles, `make_game.py --help`, Rust tests 840 s, Rust replay test 79 s, Rust build as shipped 85 s, standard-library Python tests 601 s. - Report-only checks, as in the GitHub workflow: asset policy and Clippy. The forge refused the merge while the head was behind main. So `main` (`662d061e1`) was merged into the head as `27819d656`, with the same tree the CI tested. Merged as `30a851050`.
Collaborator

Post-merge gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300): head ba8071a0c merged into main 04a838fc4, diag profile with diagnostics,dlss,mimalloc, msvc target. The merged head 27819d656 only adds a merge of main 662d061e1; the change this PR adds is byte-identical in both (same patch id for main..head). Reference: main 04a838fc4 built the same way. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data.

  • 0 device lost, 0 crash, 0 ERROR lines.
  • 35.2 frames/s over 150-300 s against 34.5 for main; median frame 28.20 ms, p99 44.8 against 45.5 ms. Pauses as in the reference, none after 150 s.
  • The mod file-writing path is not reached in this run: the runtime reports no mod running, so this run says nothing about the short-name check itself. That part rests on the PR's own tests.

Verdict: PASS, no cost.

GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: run and report by Claude Code (Claude Opus 5.5).

Post-merge gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300): head `ba8071a0c` merged into `main` `04a838fc4`, diag profile with `diagnostics,dlss,mimalloc`, msvc target. The merged head `27819d656` only adds a merge of `main` 662d061e1; the change this PR adds is byte-identical in both (same patch id for `main`..head). Reference: `main` `04a838fc4` built the same way. Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, fresh data. - 0 device lost, 0 crash, 0 ERROR lines. - 35.2 frames/s over 150-300 s against 34.5 for `main`; median frame 28.20 ms, p99 44.8 against 45.5 ms. Pauses as in the reference, none after 150 s. - The mod file-writing path is not reached in this run: the runtime reports no mod running, so this run says nothing about the short-name check itself. That part rests on the PR's own tests. Verdict: PASS, no cost. GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40. AI-assisted: run and report by Claude Code (Claude Opus 5.5).
Sign in to join this conversation.
No description provided.