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

Open
github-bot wants to merge 1 commit from github-bot/gh-3372 into main AGit
Owner

@⁠Kal0s-design on GitHub · 2026-12-03 17:35 UTC · original
Kal0s-design:fix/lua-write-file-short-names → main · +111 −7 · 3 files · 1 commits · open

Claimed in the coordination issue as: D3D12-LUA-WRITE-FILE-SHORT-NAMES (#2570)

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

**@⁠Kal0s-design** on GitHub · 2026-12-03 17:35 UTC · [original](https://github.com/ProjectLeonida/mandy/pull/3372) `Kal0s-design:fix/lua-write-file-short-names` → `main` · +111 −7 · 3 files · 1 commits · open Claimed in the coordination issue as: D3D12-LUA-WRITE-FILE-SHORT-NAMES (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/2570) ### 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)
On a volume that keeps 8.3 short names, NTFS also calls mod.json
MOD~1.JSO. That is a plain relative name: it is not mod.json and jso is
not a blocked extension, so write_file let a mod overwrite its own
manifest through it.

The manifest and extension checks are now one function. When the path
leads to a file that is there, write_file also runs it on the name that
file has (canonicalized, relative to the mod's folder). The check on the
name the mod passes stays as it was. The short name of an ordinary file
is still written.

The tests run on Windows and skip where the volume makes no short names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 17:39:12 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3372/head:github-bot/gh-3372'
git switch 'github-bot/gh-3372'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3372'
git switch 'github-bot/gh-3372'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3372'
git switch 'github-bot/gh-3372'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3372'
git switch 'main'
git merge --squash 'github-bot/gh-3372'
git switch 'main'
git merge --ff-only 'github-bot/gh-3372'
git switch 'main'
git merge 'github-bot/gh-3372'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida!3372
No description provided.