runtime: harden title_window_plan and ArenaBlocks bounds/overflow checks (RT-TITLE-WINDOW-AND-ARENA-BOUNDS) #1785
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1785
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1785/head"
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?
@IlyassRS3 on GitHub · 2026-11-25 12:08 UTC · original
IlyassRS3:fix/rt-title-window-and-arena-bounds→main· +177 −15 · 5 files · 1 commits · merged 2026-11-25 14:40 UTCSummary
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 passFix edge-case arithmetic and boundary bugs in the title-memory window planner and GPU address arena allocator: 1. runtime/src/title_window_plan.h: - title_window_range(): reject va < lo (previously returned a range starting at lo > va that excluded va, causing va - range.start to underflow in resolve_title_memory), reject most == 0 (avoiding std::clamp(want, 1, 0) UB), require power-of-two align, and avoid UINT64_MAX - want - align unsigned underflow when computing end. - title_pool_extent(): reject non-power-of-two align and unreadable requests (readable_end <= va) before rounding end up to align, and enforce the most cap after alignment rounding so out.size <= most always holds and out contains va. 2. runtime/src/arena_blocks.h: - Make align_up() overflow-checked so high alignments or keep_out_end near UINT64_MAX cannot wrap to 0 and trigger an infinite loop in ArenaBlocks::allocate(). - Guard against non-advancing keep_out_end <= start in allocate(). - Make consistent() safe against reserved_ > size_ underflow and free_bytes_ + live_bytes overflow. Extend runtime/test/arena_blocks_test.cpp and add portable runtime/test/title_window_plan_bounds_test.cpp. Item: RT-TITLE-WINDOW-AND-ARENA-BOUNDS@copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 12:08 UTC · original · reviewed
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
@lixonik on GitHub · 2026-11-25 12:13 UTC · original · reviewed
Independent A/B at
eb4c4204against its base0d80bc5d. The new bounds suite fails against the base at the check for a requested address below the lower bound. On this head, both the new bounds suite and arena_blocks_test passed with GCC and UBSan under Ubuntu/WSL. The existing title_window_plan_test also built with MSVC and passed on native Windows, including its budget and paired-view mapping controls.AI-assisted. CPU-only synthetic cases.
@aslan2142 on GitHub · 2026-11-25 14:40 UTC · original
Merged. Thank you, @IlyassRS3, and thanks to @lixonik for the A/B.
va < locheck covers a real, race-only path (a range added by another thread between theshader_vacheck andgap()), which underflowed before.title_window_plan_boundspasses.main: nothing goes from pass to fail.end <= vaintitle_window_rangeandend <= startintitle_pool_extentcan never fire after the earlier checks, and the!mostandraw_endchecks have no case that fails without them.mainc3b58ef03+eb4c4204e: it merges cleanly; the semantic suite passes (489 files, 6,288 tests, 0 files failed); the 14 docs and writer tests pass;check_no_game_data.pyis clean on the 5 changed files.AI-assisted (Claude Code, Claude Opus 5.5).