D3D12-LUA-LINKS-STAY-IN-THE-FOLDER: require and the script refuse a link that leads out #3051

Merged
imShangLi merged 3 commits from upstream-pr/3051 into main 2026-12-02 13:59:00 +00:00
imShangLi commented 2026-12-02 05:43:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T05:43:40Z.


Claimed in the coordination issue as: D3D12-LUA-LINKS-STAY-IN-THE-FOLDER

What and why

The Lua modding API (d3d12/crates/leonida-lua) keeps a mod inside its own folder: leonida.read_file and
leonida.write_file join the name to the folder, canonicalise it and refuse a link that leads out of it. Two paths
did not go through that check:

  • require() joined the module name to the folder and asked Path::is_file(), which follows links;
  • the script the manifest names ("script") was read the same way.

So a link inside the mod's folder led to a file outside it, and that file was then run as Lua in the mod's
environment. Measured with a link in the mod's folder: require("helper") returned the module from outside the
folder, while leonida.read_file("helper.lua") refused the very same link.

The change moves the check to manifest::inside() (next to safe_relative, which it uses) and routes every path to a
file of the mod's own folder through it: require, the manifest's script, read_file, write_file. A link that
points inside the folder still works, and a mods folder that is itself a link still works.

Tested

  • cargo test -p leonida-lua --locked - 41 tests, 0 failed. Fedora 45, Rust 1.98.1, no title, no game files.
  • python3 -I scripts/red_green.py fix/d3d12-lua-require-inside-folder --crate leonida-lua - the repository's own
    red/green tool: red then green. The red side is origin/main (8422def7) with the new test; there the mod loads
    the module from outside its folder and the test fails.
  • cargo clippy -p leonida-lua --all-targets --locked - no new warning (the crate's two Default warnings in
    input.rs, and leonida-menu's three, are on main too).
  • python3 -I scripts/check_no_game_data.py on the five changed files - clean.
  • The d3d12 workflow (.github/workflows/d3d12.yml) runs cargo test --workspace --exclude xtask on
    windows-latest for a change under d3d12/. The new test needs to make a link, which a Windows runner only allows
    with the right; where that is not the case it skips itself rather than failing.

What I did not check: this has not run in the running title (the Lua API has never been run there -
docs/lua-modding.md, "Not tried yet"), and it touches no GPU code, so no GPU was involved.

GPUs tested: n/a (no GPU code; the crate's tests run on the CPU)

AI-assisted: yes - MiniMax M3.1 Flash (the change and the test); an independent read-only reviewer agent audited the
diff, the edge cases and the red/green power of the test.

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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5600634245 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3051). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-02T05:43:40Z. --- Claimed in the coordination issue as: [D3D12-LUA-LINKS-STAY-IN-THE-FOLDER](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7335556501) ### What and why The Lua modding API (`d3d12/crates/leonida-lua`) keeps a mod inside its own folder: `leonida.read_file` and `leonida.write_file` join the name to the folder, canonicalise it and refuse a link that leads out of it. Two paths did not go through that check: - `require()` joined the module name to the folder and asked `Path::is_file()`, which follows links; - the script the manifest names (`"script"`) was read the same way. So a link inside the mod's folder led to a file **outside** it, and that file was then run as Lua in the mod's environment. Measured with a link in the mod's folder: `require("helper")` returned the module from outside the folder, while `leonida.read_file("helper.lua")` refused the very same link. The change moves the check to `manifest::inside()` (next to `safe_relative`, which it uses) and routes every path to a file of the mod's own folder through it: `require`, the manifest's script, `read_file`, `write_file`. A link that points **inside** the folder still works, and a mods folder that is itself a link still works. ### Tested - `cargo test -p leonida-lua --locked` - 41 tests, 0 failed. Fedora 45, Rust 1.98.1, no title, no game files. - `python3 -I scripts/red_green.py fix/d3d12-lua-require-inside-folder --crate leonida-lua` - the repository's own red/green tool: **red then green**. The red side is `origin/main` (8422def7) with the new test; there the mod loads the module from outside its folder and the test fails. - `cargo clippy -p leonida-lua --all-targets --locked` - no new warning (the crate's two `Default` warnings in `input.rs`, and `leonida-menu`'s three, are on `main` too). - `python3 -I scripts/check_no_game_data.py` on the five changed files - clean. - The `d3d12` workflow (`.github/workflows/d3d12.yml`) runs `cargo test --workspace --exclude xtask` on `windows-latest` for a change under `d3d12/`. The new test needs to make a link, which a Windows runner only allows with the right; where that is not the case it skips itself rather than failing. What I did not check: this has not run in the running title (the Lua API has never been run there - `docs/lua-modding.md`, "Not tried yet"), and it touches no GPU code, so no GPU was involved. GPUs tested: n/a (no GPU code; the crate's tests run on the CPU) AI-assisted: yes - MiniMax M3.1 Flash (the change and the test); an independent read-only reviewer agent audited the diff, the edge cases and the red/green power of the test. ### 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.
Kal0s-design commented 2026-12-02 06:16:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T06:16:54Z.


Windows 11, MSVC toolchain 1.98.1. Head 9d962894c merged into current main 0ae5a2664: the merge is clean.

  • cargo test -p leonida-lua --locked: 41 passed, 0 failed.
  • On this account Windows refuses to make a file symlink without admin rights ("Administrator privilege required"). So link() returns false and a_link_out_of_the_mods_folder_is_not_a_module_and_not_a_script returns early. It passes here without checking anything. Whether it checks anything on windows-latest depends on the runner's rights.

A directory junction (mklink /J) needs no rights on Windows, so I used one instead. I added a scratch test and removed it afterwards. It puts a junction lib in the mod's folder that points to a folder outside, which holds helper.lua and main.lua:

main's api.rs/manifest.rs/runtime.rs this PR
pcall(require, "lib.helper") true, from outside false, "lib/helper.lua leads out of the mod's folder"
leonida.read_file("lib/helper.lua") refused refused
manifest "script": "lib/main.lua" runs (ran), status Running not run, Failed("lib/main.lua leads out of the mod's folder")
junction inner → a folder inside the mod, require("inner.helper") true, inside true, inside

So on Windows the hole is open to junctions as well as file links, and the change closes it while a junction that stays inside still works. A suggestion: the test's Windows branch could make a junction to a folder instead of a file symlink. Then it runs without admin rights rather than skipping.

cargo clippy -p leonida-lua --all-targets --locked: no warning.

Not checked: the running title.

GPUs tested: n/a (CPU unit tests)

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7336837168 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3051#issuecomment-7336837168). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-02T06:16:54Z. --- Windows 11, MSVC toolchain 1.98.1. Head `9d962894c` merged into current `main` `0ae5a2664`: the merge is clean. - `cargo test -p leonida-lua --locked`: 41 passed, 0 failed. - On this account Windows refuses to make a file symlink without admin rights ("Administrator privilege required"). So `link()` returns false and `a_link_out_of_the_mods_folder_is_not_a_module_and_not_a_script` returns early. It passes here without checking anything. Whether it checks anything on `windows-latest` depends on the runner's rights. A **directory junction** (`mklink /J`) needs no rights on Windows, so I used one instead. I added a scratch test and removed it afterwards. It puts a junction `lib` in the mod's folder that points to a folder outside, which holds `helper.lua` and `main.lua`: | | `main`'s `api.rs`/`manifest.rs`/`runtime.rs` | this PR | |---|---|---| | `pcall(require, "lib.helper")` | `true`, `from outside` | `false`, "`lib/helper.lua` leads out of the mod's folder" | | `leonida.read_file("lib/helper.lua")` | refused | refused | | manifest `"script": "lib/main.lua"` | runs (`ran`), status `Running` | not run, `Failed("`lib/main.lua` leads out of the mod's folder")` | | junction `inner` → a folder **inside** the mod, `require("inner.helper")` | `true`, `inside` | `true`, `inside` | So on Windows the hole is open to junctions as well as file links, and the change closes it while a junction that stays inside still works. A suggestion: the test's Windows branch could make a junction to a folder instead of a file symlink. Then it runs without admin rights rather than skipping. `cargo clippy -p leonida-lua --all-targets --locked`: no warning. Not checked: the running title. GPUs tested: n/a (CPU unit tests) AI-assisted: yes (Claude Code).
imShangLi commented 2026-12-02 08:27:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T08:27:59Z.


Thank you for the Windows run, and for the junction suggestion — it was the right one: a file symlink needs rights this account does not have, so the case did not run there at all.

Both link cases now run everywhere:

  • A directory link (a symlink to a folder on Unix, a junction on Windows) that leads out of the mod's folder is refused, for a module (require("lib.helper")) and for the script the manifest names (lib/main.lua). On Windows the junction is made with mklink /J, which needs no rights.
  • The file link stays as it was, for the platforms that allow one.

While I was in the test I found that the manifest half of the file-link case never ran: folder() writes a main.lua into the mod, so the link for the script could not be made and the case returned early. The mod is made by hand there now, so the script the manifest names is the link. The assertion there was wrong as well — the mod is disabled with the reason (disabled (the other mods go on): main.lua leads out of the mod's folder), not silent — so the test checks the message and the status.

Red/green on Fedora 45 with cargo test -p leonida-lua --locked:

  • With api.rs, manifest.rs and runtime.rs back to main and the new tests kept: a_link_out_of_the_mods_folder_is_not_a_module_and_not_a_script and a_directory_link_out_of_the_mods_folder_is_not_a_module_and_not_a_script fail (40 passed, 2 failed).
  • With the change: 42 passed, 0 failed.

cargo clippy -p leonida-lua --all-targets --locked: no new warning (the two Pads::new ones in input.rs are on main too). cargo fmt --check shows only the two pre-existing diffs in api.rs.

Head 856615ce.

GPUs tested: n/a (CPU unit tests)

AI-assisted: yes (MiniMax M3.1 Flash).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7339488440 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3051#issuecomment-7339488440). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-02T08:27:59Z. --- Thank you for the Windows run, and for the junction suggestion — it was the right one: a file symlink needs rights this account does not have, so the case did not run there at all. Both link cases now run everywhere: - **A directory link** (a symlink to a folder on Unix, a junction on Windows) that leads out of the mod's folder is refused, for a module (`require("lib.helper")`) and for the script the manifest names (`lib/main.lua`). On Windows the junction is made with `mklink /J`, which needs no rights. - **The file link** stays as it was, for the platforms that allow one. While I was in the test I found that the manifest half of the file-link case never ran: `folder()` writes a `main.lua` into the mod, so the link for the script could not be made and the case returned early. The mod is made by hand there now, so the script the manifest names is the link. The assertion there was wrong as well — the mod is *disabled* with the reason (`disabled (the other mods go on): `main.lua` leads out of the mod's folder`), not silent — so the test checks the message and the status. Red/green on Fedora 45 with `cargo test -p leonida-lua --locked`: - With `api.rs`, `manifest.rs` and `runtime.rs` back to `main` and the new tests kept: `a_link_out_of_the_mods_folder_is_not_a_module_and_not_a_script` and `a_directory_link_out_of_the_mods_folder_is_not_a_module_and_not_a_script` fail (40 passed, 2 failed). - With the change: 42 passed, 0 failed. `cargo clippy -p leonida-lua --all-targets --locked`: no new warning (the two `Pads::new` ones in `input.rs` are on `main` too). `cargo fmt --check` shows only the two pre-existing diffs in `api.rs`. Head `856615ce`. GPUs tested: n/a (CPU unit tests) AI-assisted: yes (MiniMax M3.1 Flash).
Kal0s-design commented 2026-12-02 08:34:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T08:34:37Z.


Re-checked 856615ce7 on Windows (no admin rights, so file symlinks are still refused here), merged into current main: the merge is clean.

  • cargo test -p leonida-lua --locked: 42 passed, 0 failed.
  • The new a_directory_link_out_of_the_mods_folder_is_not_a_module_and_not_a_script makes its junction and runs. With api.rs, manifest.rs and runtime.rs put back to main, it fails at tests.rs:974 (41 passed, 1 failed). With the change it passes. So the Windows case is a real red/green now, not a skip.

GPUs tested: n/a (CPU unit tests)

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7339638555 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3051#issuecomment-7339638555). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-02T08:34:37Z. --- Re-checked `856615ce7` on Windows (no admin rights, so file symlinks are still refused here), merged into current `main`: the merge is clean. - `cargo test -p leonida-lua --locked`: 42 passed, 0 failed. - The new `a_directory_link_out_of_the_mods_folder_is_not_a_module_and_not_a_script` makes its junction and runs. With `api.rs`, `manifest.rs` and `runtime.rs` put back to `main`, it fails at `tests.rs:974` (41 passed, 1 failed). With the change it passes. So the Windows case is a real red/green now, not a skip. GPUs tested: n/a (CPU unit tests) AI-assisted: yes (Claude Code).
imShangLi commented 2026-12-02 10:08:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T10:08:55Z.


Thank you for re-checking 856615ce7 — that the junction case now makes its junction on Windows and fails on main at tests.rs:974 is exactly what I was after: the case runs there instead of skipping.

Two things worth noting:

  • The file-symlink case still skips on Windows without rights (a symlink to a file needs them; a junction is a directory link, so it needs none). The two shapes reach the same check — the canonical path of the file the mod names — so the junction case covers the ground there, and the file case still runs on Linux and macOS.
  • The manifest half of the file-link case was dead before your suggestion: folder() writes a main.lua into the mod, so the link for the script could not be made and the case returned early. That is fixed too — the mod is made by hand there now, and the assertion checks the message (disabled (the other mods go on): main.lua leads out of the mod's folder) and the status, which is what the runtime does.

Head 856615ce; nothing else changed since your run.

GPUs tested: n/a (CPU unit tests)

AI-assisted: yes (MiniMax M3.1 Flash).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7342035464 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3051#issuecomment-7342035464). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-02T10:08:55Z. --- Thank you for re-checking `856615ce7` — that the junction case now *makes* its junction on Windows and fails on `main` at `tests.rs:974` is exactly what I was after: the case runs there instead of skipping. Two things worth noting: - The file-symlink case still skips on Windows without rights (a symlink to a *file* needs them; a junction is a directory link, so it needs none). The two shapes reach the same check — the canonical path of the file the mod names — so the junction case covers the ground there, and the file case still runs on Linux and macOS. - The manifest half of the file-link case was dead before your suggestion: `folder()` writes a `main.lua` into the mod, so the link for the script could not be made and the case returned early. That is fixed too — the mod is made by hand there now, and the assertion checks the message (`disabled (the other mods go on): `main.lua` leads out of the mod's folder`) and the status, which is what the runtime does. Head `856615ce`; nothing else changed since your run. GPUs tested: n/a (CPU unit tests) AI-assisted: yes (MiniMax M3.1 Flash).
MoonEyes commented 2026-12-02 13:16:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:16:15Z.


RUN (in game, grouped): this head 856615ce7 was merged with git merge --no-ff, together with nine other rendering pull requests, onto main f6dd2242e (no conflicts), and the d3d12 layer was rebuilt from that tree (diag profile, with DLSS). RTX 4060 8 GB, driver 610.88, Windows 11; scripts/play-d3d12.ps1 -SeriesS -Resolution 1080 -FrameGen 2, low-memory profile, keyboard-driven entry into the world and a walking route.

  • At least 381 s in the world (time limit 330 s, then the run script stopped the game): no device loss, no unhandled exception, no hang or GPU stall in the log.
  • Rendering 14.7 frames/s median over the last 240 s (a single earlier run with the same launcher options on a different tree: 15.2).
  • Limits: one run, grouped, so a failure would not have named one pull request; the picture was not checked; free RAM was about 1.2 GB during the run.

Heads in this run: #2854 81a6e94a9, #2936 68215ad0b, #2939 561bbc19c, #2997 ef429f923, #3043 915d4d5aa, #3045 cb30a595a, #3046 0f19a0819, #3047 c33e5b48e, #3048 2ab0b4b9d, #3051 856615ce7.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7346611461 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3051#issuecomment-7346611461). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T13:16:15Z. --- RUN (in game, grouped): this head `856615ce7` was merged with `git merge --no-ff`, together with nine other rendering pull requests, onto `main` `f6dd2242e` (no conflicts), and the d3d12 layer was rebuilt from that tree (diag profile, with DLSS). RTX 4060 8 GB, driver 610.88, Windows 11; `scripts/play-d3d12.ps1 -SeriesS -Resolution 1080 -FrameGen 2`, low-memory profile, keyboard-driven entry into the world and a walking route. - At least 381 s in the world (time limit 330 s, then the run script stopped the game): no device loss, no unhandled exception, no hang or GPU stall in the log. - Rendering 14.7 frames/s median over the last 240 s (a single earlier run with the same launcher options on a different tree: 15.2). - Limits: one run, grouped, so a failure would not have named one pull request; the picture was not checked; free RAM was about 1.2 GB during the run. Heads in this run: #2854 81a6e94a9, #2936 68215ad0b, #2939 561bbc19c, #2997 ef429f923, #3043 915d4d5aa, #3045 cb30a595a, #3046 0f19a0819, #3047 c33e5b48e, #3048 2ab0b4b9d, #3051 856615ce7. AI-assisted (Claude Code, Claude Opus 5.5)
MoonEyes commented 2026-12-02 13:22:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:22:20Z.


Merging. Head 856615ce7 merges cleanly with main bf7886746 and does not force a rebase of #2566. Checked on head 856615ce7: all 6 CI checks green; third-party red/green by Kal0s-design on this head; an in-game run of at least 381 s with this head merged onto main f6dd2242e (grouped with nine other rendering pull requests, comment above) showed no device loss, no unhandled exception and no hang; item claimed in the coordination issue; author has earlier merged pull requests; conflict-free merge against main. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7346770710 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3051#issuecomment-7346770710). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T13:22:20Z. --- Merging. Head `856615ce7` merges cleanly with `main` `bf7886746` and does not force a rebase of #2566. Checked on head 856615ce7: all 6 CI checks green; third-party red/green by Kal0s-design on this head; an in-game run of at least 381 s with this head merged onto main f6dd2242e (grouped with nine other rendering pull requests, comment above) showed no device loss, no unhandled exception and no hang; item claimed in the coordination issue; author has earlier merged pull requests; conflict-free merge against main. Merged by MoonEyes. AI-assisted (Claude Code).
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!3051
No description provided.