The dropped images were 20 of 64 MB, each filled pixel by pixel. Under the
GCC -O0 --coverage build that sometimes took longer than the 20 s a screen
has to draw, so the check got -1. 4 dropped images, twice the memory of a
screen, still prove that dropped images don't count.
import and module are contextual keywords of C++20 modules. The text
loaders of the scene nodes (shape_node, lines_node, road_node,
junction_node, roadpoint_node, sweep_node) become import_from(), the
WASM module of the screen host's cache entry and of load() becomes
wasm_module, and the path of the written test module becomes
module_path. Renames only.
A %bxy at the end of a pattern (or before what always matches) was costed
as one pass over the subject, but matchbalance walks to the end of the
subject from every opening character nothing closes: ("("):rep(1e6):find("%b()")
was let through and ran for hours in C, past the instruction hook.
A %b now multiplies wherever it stands. With the subject at hand it counts
the longest way from an opening character to its closing one, or, when it is
tried once from each position, the ways from all of them over the positions:
a long text of short balanced pairs stays cheap, one that doesn't balance is
refused.
- replacement_length() popped nothing after lua_getmetatable() pushed a metatable, so gsub got it
as its 4th argument ("bad argument #4 to 'gsub'"); it is popped now.
- lua_pattern_cost(): a repetition followed by what always matches (as the first %s* of
"^%s*(.-)%s*$") is tried once and doesn't multiply; a repetition of a character or a %class
right before the final '$' counts the longest run of it in the subject, not the subject. The
trim of a 10 KB line of words is allowed, a long run of spaces is still refused (it takes the
square of the run). The doc names a trim that is linear on any string.
- the doc says every concatenation within one hook interval is made whole before the memory check.
- no newproxy: LuaJIT runs a __gc without the hook, at any allocation and
in lua_close, so a looping finalizer hung the worker. a table's __gc
isn't run, ffi isn't opened: the screens have no finalizer of their own
- render and init of the script's table are read inside the protected,
counted call, as is the state table of a refresh: an __index that fails
or loops switches the screen off instead of ending the program, and one
that gives render works
- string.find, match, gmatch and gsub are refused when the steps they may
take at worst (script_screens::lua_pattern_cost) are over 1e8, about a
tenth of a second of LuaJIT's backtracking
- a screen holds at most 128 MB, its heap and the pixels of its images,
fonts and sprites: the hook checks it with a full collection, the api
reserves pixels before making them, and string.format, table.concat and
string.gsub refuse a result over it from the lengths of their arguments.
where LuaJIT takes an allocator of the game's (2.1 GC64) the heap gets
one that refuses past twice the limit, which also stops a single large
concatenation; LuaJIT 2.0 on x64 takes none
- xpcall is made in Lua on top of pcall, so a coroutine yields across it
- the limits go into limit_libraries(), apart from opening the libraries
- Lua: once the instruction budget of a call is spent, the count hook
runs at every instruction and raises again, so pcall, nested pcall and
coroutine.resume can't swallow the limit; xpcall is rebuilt on pcall
so its handler runs after the error left f, while the hook works
- Lua: the metatables of eu07.image/font/sprite are locked
(__metatable = false); __gc destroys only an object of its own type,
once
- Lua: read_png checks the size with stbi_info before decoding
- Lua: string.rep makes no string over 1 MiB
- Lua and WASM: at most 64 commands per call, names up to 64 bytes,
32 log lines per call cut at 1024 bytes; the drops are logged once
- fonts: a glyph wider than 4096 is skipped; more than 4096 glyphs,
8192 columns or an image side over 4096 refuse the font; cut_glyph
reads only the columns inside the image
- the script path from the .mmd (cab screens, destination signs,
make: textures) must stay inside the game folder; the files a screen
reads, its script and its module must be regular files of 16 MiB at
most
Tests for each in test_script_screen_host.cpp, test_script_screen_drawing.cpp
and test_script_screens.cpp; the test stubs can capture the log.
* fix(scripting): forward the object in push_object of the Lua screens (cpp:S5417)
push_object takes a forwarding reference and called std::move on it, which
SonarCloud reports as a blocker bug. It only worked because every caller
passes an rvalue: with an lvalue Type_ is deduced as a reference, and
new Type_(std::move(Object)) doesn't even compile.
The object is now forwarded, and the userdata is sized and built for
std::remove_cvref_t<Type_>, the type collect<> and check_object<> are used
with: an rvalue is moved in, an lvalue would be copied. Every caller passes
an rvalue of lua_image, bitmap_font or glyph, so they move the object in
exactly as before.
* fix(simulation): turbidity from the overcast without branches of the same value (cpp:S3923)
The chain of conditionals setting Global.fTurbidity had pairs of branches
with the same result (<= 0.10 and <= 0.20 both 4, and so on, the last two
both 9), which SonarCloud reports as a bug. The thresholds that changed
nothing are gone and the mapping is a small function: up to 0.20 gives 4,
up to 0.40 5, up to 0.60 6, up to 0.70 7, up to 0.80 8, anything else 9.
The comparisons are the same ones, in the same order, so every overcast
value gives the turbidity it gave before.
* test: script screen tests keep their files in the build folder, not in the temporary one (cpp:S5443)
The folders of the script screen host tests were made in the system's
temporary directory, and the sandbox test put its "outside.txt" straight
into that directory. SonarCloud reports both uses as vulnerabilities:
the directory is writable by everyone.
The folders are now made in the build folder of the unit tests, passed to
them as EU07_UNIT_TESTS_SCRATCH, the way EU07_UNIT_TESTS_DATA is. The
scripts are one level down in the folder of a test, so the file the sandbox
test puts outside the folder of the scripts is still inside the folder of
the test and goes with it. Nothing depends on the working directory, and
nothing is left behind.