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

Open
Kal0s-design wants to merge 1 commit from upstream-pr/3372 into main
Kal0s-design commented 2026-12-03 17:35:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-03T17:35:54Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5631701141 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3372). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-03T17:35:54Z. --- 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)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3372:upstream-pr/3372'
git switch 'upstream-pr/3372'

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 'main'
git merge --no-ff 'upstream-pr/3372'
git switch 'upstream-pr/3372'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3372'
git switch 'upstream-pr/3372'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3372'
git switch 'main'
git merge --squash 'upstream-pr/3372'
git switch 'main'
git merge --ff-only 'upstream-pr/3372'
git switch 'main'
git merge 'upstream-pr/3372'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!3372
No description provided.