D3D12-LUA-LINKS-STAY-IN-THE-FOLDER: require and the script refuse a link that leads out #3051
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3051"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_fileandleonida.write_filejoin the name to the folder, canonicalise it and refuse a link that leads out of it. Two pathsdid not go through that check:
require()joined the module name to the folder and askedPath::is_file(), which follows links;"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 thefolder, while
leonida.read_file("helper.lua")refused the very same link.The change moves the check to
manifest::inside()(next tosafe_relative, which it uses) and routes every path to afile of the mod's own folder through it:
require, the manifest's script,read_file,write_file. A link thatpoints 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 ownred/green tool: red then green. The red side is
origin/main(8422def7) with the new test; there the mod loadsthe module from outside its folder and the test fails.
cargo clippy -p leonida-lua --all-targets --locked- no new warning (the crate's twoDefaultwarnings ininput.rs, andleonida-menu's three, are onmaintoo).python3 -I scripts/check_no_game_data.pyon the five changed files - clean.d3d12workflow (.github/workflows/d3d12.yml) runscargo test --workspace --exclude xtaskonwindows-latestfor a change underd3d12/. The new test needs to make a link, which a Windows runner only allowswith 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T06:16:54Z.
Windows 11, MSVC toolchain 1.98.1. Head
9d962894cmerged into currentmain0ae5a2664: the merge is clean.cargo test -p leonida-lua --locked: 41 passed, 0 failed.link()returns false anda_link_out_of_the_mods_folder_is_not_a_module_and_not_a_scriptreturns early. It passes here without checking anything. Whether it checks anything onwindows-latestdepends 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 junctionlibin the mod's folder that points to a folder outside, which holdshelper.luaandmain.lua:main'sapi.rs/manifest.rs/runtime.rspcall(require, "lib.helper")true,from outsidefalse, "lib/helper.lualeads out of the mod's folder"leonida.read_file("lib/helper.lua")"script": "lib/main.lua"ran), statusRunningFailed("lib/main.lualeads out of the mod's folder")inner→ a folder inside the mod,require("inner.helper")true,insidetrue,insideSo 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).
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:
require("lib.helper")) and for the script the manifest names (lib/main.lua). On Windows the junction is made withmklink /J, which needs no rights.While I was in the test I found that the manifest half of the file-link case never ran:
folder()writes amain.luainto 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.lualeads 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:api.rs,manifest.rsandruntime.rsback tomainand the new tests kept:a_link_out_of_the_mods_folder_is_not_a_module_and_not_a_scriptanda_directory_link_out_of_the_mods_folder_is_not_a_module_and_not_a_scriptfail (40 passed, 2 failed).cargo clippy -p leonida-lua --all-targets --locked: no new warning (the twoPads::newones ininput.rsare onmaintoo).cargo fmt --checkshows only the two pre-existing diffs inapi.rs.Head
856615ce.GPUs tested: n/a (CPU unit tests)
AI-assisted: yes (MiniMax M3.1 Flash).
Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T08:34:37Z.
Re-checked
856615ce7on Windows (no admin rights, so file symlinks are still refused here), merged into currentmain: the merge is clean.cargo test -p leonida-lua --locked: 42 passed, 0 failed.a_directory_link_out_of_the_mods_folder_is_not_a_module_and_not_a_scriptmakes its junction and runs. Withapi.rs,manifest.rsandruntime.rsput back tomain, it fails attests.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).
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 onmainattests.rs:974is exactly what I was after: the case runs there instead of skipping.Two things worth noting:
folder()writes amain.luainto 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.lualeads 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).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:16:15Z.
RUN (in game, grouped): this head
856615ce7was merged withgit merge --no-ff, together with nine other rendering pull requests, ontomainf6dd2242e(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.Heads in this run: #2854
81a6e94a9, #293668215ad0b, #2939561bbc19c, #2997ef429f923, #3043915d4d5aa, #3045cb30a595a, #30460f19a0819, #3047c33e5b48e, #30482ab0b4b9d, #3051856615ce7.AI-assisted (Claude Code, Claude Opus 5.5)
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:22:20Z.
Merging. Head
856615ce7merges cleanly withmainbf7886746and does not force a rebase of #2566. Checked on head856615ce7: 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 mainf6dd2242e(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).