Repository navigation
Conversation
…ptions are checked The range of leonida.memory.scan was checked against the process, not against the work it causes: a mod could ask for the whole user range (128 TiB) and the scan's time was refunded to the call budget, so nothing stopped it. The one thread that runs every mod then sat in the scan for hours, and the other mods, the menu callbacks and the reload path waited for it. - one scan covers at most 256 MiB (the whole image, when it is bigger) - start, size and max are whole numbers: a negative one or another kind of value is refused with the reason, not taken for something else - without a size, the range reaches the end of the image (it ended 100 bytes short when it started below the image)
- the test for the default range stands on its own, so it shows red without the fix (on the base the mod is disabled by the typed option before it gets there) - the doc says what is really refused: a numeric string is a whole number and is taken
- the doc says that a string which names a whole number is taken as that number, so the sentence is true - the test covers a negative size and a negative max too
Contributor
|
A native Windows run, since the description's run was on Fedora. Windows 11, MSVC toolchain 1.98.1. Head
Not checked: the running title, the same as in the description. GPUs tested: n/a (CPU unit tests) AI-assisted: yes (Claude Code). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as: D3D12-LUA-MEMORY-SCAN-BOUNDS
(#2683 is open on the same crate, on
write_file; this one is on thescanbinding, they do not overlap.)What and why
leonida.memory.scan(the Lua modding API,d3d12/crates/leonida-lua) let a mod ask for a range covering the whole64-bit user address space:
{start = 0x10000, size = 0x7FFFFFFF0000}- 128 TiB less 64 KiB - is accepted today,because the range is checked against the process (
LOWEST/HIGHEST) and never against the work it causes.The time a scan takes is refunded to the mod's call budget (
guard.pause(began.elapsed()), so that "a long scan isnot the mod's own running time"), and the instruction hook cannot see inside a native call, so nothing stopped it: the
one thread that runs every mod (
crates/leonida-lua/src/lib.rs,rt.pass) sat in the scan, and the other mods, theF4 menu callbacks and the "Reload Lua mods" path waited for it. Reading 128 TiB of address space is 34 billion page
reads; on the running title every page read is a
ReadProcessMemorycall.This change:
walk the address space;
start,sizeandmaxare whole numbers. A negative one was silently turned intosomething else (
{start = -1}scanned the whole image,{size = -1}scanned nothing) and is now refused with thereason, as is a value that is not a whole number;
size, the range reaches the end of the image. It used to besize.saturating_sub(start.saturating_sub(base)), which ends 100 bytes short of the image's top whenstartisbelow the image, so a pattern there was silently missed.
docs/lua-modding.mdsays the same.Not in this pull request: the range may still be outside the title's image (only its size is bounded), and a scan's
time is still refunded to the mod's budget - the budget is about the mod's Lua, not about the runtime's work. So a mod
that scans back to back still runs for as long as it likes, in 256 MiB steps; stopping that would mean checking the
budget inside the scan, which is a bigger change than this one.
Two behaviours change for a mod that asks for something odd:
start = -1used to mean "the image's base", and anoption that was not a number used to raise (which disables that mod). Both are now a refusal with the reason, and the
mod stays alive.
Tested
cargo test -p leonida-lua --locked- 42 tests, 0 failed (the crate's own: the sandbox, the events, the memoryAPI, the files, the menu). Fedora 45, Rust 1.98.1, no title, no game files.
python -I scripts/red_green.py fix/d3d12-lua-memory-scan-bounds --crate leonida-lua- the repository's ownred/green tool: red then green, for both new tests. The red side is
origin/main(8422def) with the newtests; they fail there and pass with the change.
cargo clippy -p leonida-lua --all-targets --locked- no new warning (the crate's twoDefaultwarnings ininput.rs, andleonida-menu's three, are onmaintoo).python -I scripts/check_no_game_data.pyon the four changed files - clean.d3d12workflow (.github/workflows/d3d12.yml) runscargo test --workspace --exclude xtaskonwindows-latestfor a change underd3d12/, so the new 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 tests); two independent read-only reviewer agents
(SenseNova 6.8 Flash, SenseNova 6.8 Flash Lite) 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.