Repository navigation
runtime: harden title_window_plan and ArenaBlocks bounds/overflow checks (RT-TITLE-WINDOW-AND-ARENA-BOUNDS) - #1785
Merged
aslan2142 merged 1 commit intoNov 25, 2026
Conversation
IlyassRS3
added a commit
to IlyassRS3/leonida
that referenced
this pull request
Nov 25, 2026
token = open("/Users/ilyass/.t3/userdata/secrets/files/c721f15a7c789b9ff6a1ec60e2682c05").read().strip()
ctx = ssl.create_default_context(cafile="/etc/ssl/cert.pem")
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/vnd.github+json",
"Content-Type": "application/json",
"User-Agent": "leonida-loop",
}
def req(url, method="GET", data=None):
r = urllib.request.Request(url, data=json.dumps(data).encode() if data is not None else None, headers=headers, method=method)
with urllib.request.urlopen(r, context=ctx, timeout=20) as resp:
return json.loads(resp.read().decode())
done = req("https://api.github.com/repos/ubiquitarianism/leonida/issues/1608/comments", "POST", {
"body": "done: `RT-TITLE-WINDOW-AND-ARENA-BOUNDS` -> ProjectLeonida#1785"
})
print("DONE_URL:", done["html_url"])
# Atomic check + claim for RT-GPU-LABEL-MEMORY-EXPAND
prs = req("https://api.github.com/repos/ubiquitarianism/leonida/pulls?state=open&per_page=100")
for p in prs:
txt = (p["title"] + " " + (p.get("body") or "")).lower()
if "gpu_label_memory" in txt:
print(f"CONFLICT_PR #{p['number']}: {p['title']}")
sys.exit(2)
issue = req("https://api.github.com/repos/ubiquitarianism/leonida/issues/1608")
last_page = max(1, (issue["comments"] + 29) // 30)
for page in range(max(1, last_page - 1), last_page + 1):
cs = req(f"https://api.github.com/repos/ubiquitarianism/leonida/issues/1608/comments?per_page=30&page={page}")
for c in cs:
if "gpu_label_memory" in c["body"].lower():
print(f"CONFLICT_COMMENT {c['id']} @{c['user']['login']}: {c['body'][:200]}")
sys.exit(2)
claim_body = (
"claiming: `RT-GPU-LABEL-MEMORY-EXPAND` — fix `leonida::label::Memory::track()` in "
"`runtime/src/gpu_label_memory.h` so growing a tracked non-heap region at the same `base` and "
"`allocation_base` updates `Region::end` in place instead of overwriting `regions_[base]` with a new "
"`shared_ptr` (which invalidated and silently dropped in-flight GPU completion value writes for that region). "
"Add portable unit test `runtime/test/gpu_label_memory_test.cpp`. No game files."
)
claim = req("https://api.github.com/repos/ubiquitarianism/leonida/issues/1608/comments", "POST", {"body": claim_body})
print("CLAIM_URL:", claim["html_url"])
print("CLAIM_ID:", claim["id"])
PY
IlyassRS3
force-pushed
the
fix/rt-title-window-and-arena-bounds
branch
from
November 25, 2026 12:09
e08a488 to
ec0d50d
Compare
…ow checks
Fix 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
IlyassRS3
force-pushed
the
fix/rt-title-window-and-arena-bounds
branch
from
November 25, 2026 12:09
ec0d50d to
eb4c420
Compare
lixonik
reviewed
Nov 25, 2026
lixonik
left a comment
Contributor
There was a problem hiding this comment.
Independent A/B at eb4c4204 against its base 0d80bc5d. 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.
Collaborator
|
Merged. Thank you, @IlyassRS3, and thanks to @lixonik for the A/B.
AI-assisted (Claude Code, Claude Opus 5.5). |
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.
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