D3D12-LUA-STRING-DUMP: a mod cannot make a precompiled chunk #3047
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3047"
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:05:07Z.
Claimed in the coordination issue as: D3D12-LUA-STRING-DUMP
What and why
docs/lua-modding.mdlistsstring.dumpunder "Not there", and saysloadtakes text chunks only "because aprecompiled chunk can take the interpreter down". The mod's own copy of the
stringlibrary does not havedump-but the state has one string metatable, and it points at the real global
stringtable. Fakinggetmetatablefor strings (
sandbox.rs) hid the metatable from the mods, but string indexing still resolves through it, so:Measured in the crate's own sandbox:
type(string.dump)isnil,type(("x").dump)isfunction, andpcall(("x").dump, function() return 42 end)returns a 105-byte binary chunk that starts with the0x1Bsignature.A mod can therefore make a precompiled chunk, which the sandbox is built to keep away from it. Today it cannot run
one back (
loadrefuses it: "attempt to load a binary chunk (mode is 't')", andrequireloads text only), so thereis no escape from it yet - but the guarantee the documentation states does not hold, and any later change that loads
a chunk in another way would turn it into the interpreter-killer the sandbox is meant to avoid.
The change: the state's string metatable points at a table without
dumpinstead of at the realstringtable, sothe real one is out of reach as well. It is set once, in
sandbox::new_lua, because all the mods share one Luastate.
Tested
cargo test -p leonida-lua --locked- 40 tests, 0 failed. Fedora 45, Rust 1.98.1, no title, no game files.python -I scripts/red_green.py fix/d3d12-lua-string-dump --crate leonida-lua- the repository's own red/greentool: red then green. The red side is
origin/main(8422def7) with the changed test; on the base the mod finds("x").dumpand the "what is forbidden is gone" test fails.cargo clippy -p leonida-lua --all-targets --locked- no new warning (the crate's twoDefaultwarnings ininput.rsare onmaintoo).python -I scripts/check_no_game_data.pyon the two changed files - clean.d3d12workflow (.github/workflows/d3d12.yml) runscargo test --workspace --exclude xtaskonwindows-latestfor a change underd3d12/, so the changed test runs there too.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 and the edge cases.
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:17:39Z.
A native Windows run, since the description's run was on Fedora. Windows 11, MSVC toolchain 1.98.1. Head
c33e5b48emerged into currentmain0ae5a2664: the merge is clean.cargo test -p leonida-lua --locked: 40 passed, 0 failed.sandbox.rsput back tomain,what_is_forbidden_is_gone_and_what_is_safe_is_therefails withleft: "gone:string.dump through a string". With the change it passes.("x").dumpandstring.dumpare bothnil. Calling("x").dump(function() end)fails with "attempt to call a nil value (field 'dump')".upper,format,rep,gsub,sub,bytegiveX 3-z abab heLLo bc 120.aassignsstring.fooin its own copy, and modbdoesn't see it as("x").foo, which staysnil. The public table the metatable now points at isn't reachable from a mod'sstring.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:28:30Z.
Thank you for the Windows run and for the scratch test with two mods in the shared state — the per-mod copy of the
stringtable (modaassigningstring.fooand modbnot seeing it) is the part I wanted checked, since the fix replaces the environment's metatable with a table of its own.Your red side confirms the new case fails without the change (
gone:string.dump through a string) and that the string methods still answer through the new metatable.Nothing to change on my side from your run. The head is still
c33e5b4and the branch isfix/d3d12-lua-string-dump.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:11Z.
RUN (in game, grouped): this head
c33e5b48ewas 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:21:45Z.
Merging. Head
c33e5b48emerges cleanly withmainbf7886746and does not force a rebase of #2566. Checked on headc33e5b48e: 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).