mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-27 00:10:51 +01:00
[PR #1785] [MERGED] runtime: harden title_window_plan and ArenaBlocks bounds/overflow checks (RT-TITLE-WINDOW-AND-ARENA-BOUNDS) #1796
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1796
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1785
Author: @IlyassRS3
Created: 11/25/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142
Base:
main← Head:fix/rt-title-window-and-arena-bounds📝 Commits (1)
eb4c420runtime: harden title_window_plan and ArenaBlocks boundary and overflow checks📊 Changes
5 files changed (+177 additions, -15 deletions)
View changed files
📝
runtime/CMakeLists.txt(+5 -0)📝
runtime/src/arena_blocks.h(+27 -8)📝
runtime/src/title_window_plan.h(+10 -7)📝
runtime/test/arena_blocks_test.cpp(+38 -0)➕
runtime/test/title_window_plan_bounds_test.cpp(+97 -0)📄 Description
Summary
Hardens boundary, alignment, and unsigned-overflow checks in
runtime/src/title_window_plan.handruntime/src/arena_blocks.h(both on the world-start title-memory mapping and GPU arena allocation path merged in #1723).RT-TITLE-WINDOW-AND-ARENA-BOUNDSRoot causes & changes
runtime/src/title_window_plan.h:title_window_range():va < lo: previously only checkedhi <= va, so whenlo > va(e.g., ifgap()returnedlo > va) it returnedtruewithrange.start = lo > va(excludingva), causingoffset + (va - range.start)inresolve_title_memoryto underflow.most == 0instead of callingstd::clamp<std::uint64_t>(want, 1, 0)(UB).alignbefore masking with~(align - 1).raw_end = va + wantand alignment round-up with separate saturation guards soUINT64_MAX - want - aligncannot underflow whenwant + alignwraps.title_pool_extent():alignand rejectreadable_end <= vabefore roundingendup toalign(previously a partial readable run ending beforevainside the same alignment page rounded up pastvaand returnedtruefor an unreadable address).mostcap after alignment rounding soout.size <= mostalways holds even whenpool_lois unaligned ormost < align, and refuse ifend <= va.runtime/src/arena_blocks.h:(value + alignment - 1) / alignment * alignmentwith overflow-checkedalign_up(value, alignment, out)so large alignments or akeep_out_endnearUINT64_MAXcannot wrap to0and spin forever insideallocate().keep_outloop cleanly ifkeep_out_end <= startinstead of stalling.consistent(live_bytes)againstsize_ < reserved_underflow andfree_bytes_ + live_bytesoverflow.runtime/test/arena_blocks_test.cpp,runtime/test/title_window_plan_bounds_test.cpp, &runtime/CMakeLists.txt:arena_blocks_testwith overflowalign_up, wrappingkeep_out_end, stagnantkeep_out_end <= start, andconsistent()bounds checks.title_window_plan_boundsCTest covering alltitle_window_fits,title_window_range, andtitle_pool_extentboundary/overflow cases without<windows.h>.Verification
title_window_plan_testrely on Windows CI).clang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/arena_blocks_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=thread -O1 runtime/test/arena_blocks_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/arena_blocks_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -fsanitize=address,undefined -O1 runtime/test/title_window_plan_bounds_test.cpp— passclang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/title_window_plan_bounds_test.cpp— passmainheaders: bothtitle_window_plan_bounds_test(va < lo) andarena_blocks_test(align_upoverflow) fail onmain, confirming regression coveragepython3 -I scripts/check_no_game_data.py runtime/src/title_window_plan.h runtime/src/arena_blocks.h runtime/test/arena_blocks_test.cpp runtime/test/title_window_plan_bounds_test.cpp runtime/CMakeLists.txt— passpython3 -I tests/test_text_write_line_endings.py— 3/3 pass🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.