title_va_alias: guard null add(), in-range gap(), empty title_overlap_end(), and bad_alloc #1699

Open
github-bot wants to merge 1 commit from github-bot/gh-1699 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 08:44 UTC · original
IlyassRS3:fix/title-va-alias-range-and-gap-guards → main · +88 −15 · 2 files · 1 commits · open

Item ID: TITLE-VA-ALIAS-RANGE-AND-GAP-GUARDS
Claim: #1608

Summary

Hardens leonida::TitleVaAliases in runtime/src/title_va_alias.h and adds regressions to runtime/test/title_va_alias_test.cpp:

  • Reject null title_va in add(): matches add_title_memory(), resolve(), note(), and want_buffer() (previously add(0, size, arena) inserted a range at 0, making shader_va(0) non-zero while resolve(0) returned 0).
  • Return empty [va, va) from gap(va, lo, hi) when va lies inside an existing range: previously lo was set to prev->second.end > va, breaking lo <= va <= hi and allowing callers that clamp a window around va to underflow end - start.
  • Return 0 from title_overlap_end(lo, hi) when lo >= hi: empty/inverted half-open intervals [lo, hi) previously reported an overlap whenever lo lay inside a title memory range.
  • Strong exception safety in add() and add_title_memory(): pre-allocate the replacement std::map node via extract() before erasing overlapping entries, so std::bad_alloc never leaves ranges_ / memory_ partially erased or count_ out of sync with ranges_.size().

Verification

  • clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=undefined runtime/test/title_va_alias_test.cpp -> exit 0, all checks pass, 0 warnings / 0 UBSan issues.

  • Mutation check against unpatched main (git show main:runtime/src/title_va_alias.h with updated title_va_alias_test.cpp) -> exit 1 (!a.add(0, size, arena) fails immediately; gap(), title_overlap_end(), and both bad_alloc checks also fail on unpatched main).

  • python3 -I scripts/check_no_game_data.py runtime/src/title_va_alias.h runtime/test/title_va_alias_test.cpp -> OK.

  • python3 -m compileall -q make_game.py tools tests and python3 -I tests/test_text_write_line_endings.py -> OK (3/3).

  • AI-assisted: yes

  • GPUs tested: none (CPU-only portable title_va_alias_test; no game files)

**@⁠IlyassRS3** on GitHub · 2026-11-25 08:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1699) `IlyassRS3:fix/title-va-alias-range-and-gap-guards` → `main` · +88 −15 · 2 files · 1 commits · open Item ID: `TITLE-VA-ALIAS-RANGE-AND-GAP-GUARDS` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ## Summary Hardens `leonida::TitleVaAliases` in `runtime/src/title_va_alias.h` and adds regressions to `runtime/test/title_va_alias_test.cpp`: - **Reject null `title_va` in `add()`**: matches `add_title_memory()`, `resolve()`, `note()`, and `want_buffer()` (previously `add(0, size, arena)` inserted a range at 0, making `shader_va(0)` non-zero while `resolve(0)` returned 0). - **Return empty `[va, va)` from `gap(va, lo, hi)` when `va` lies inside an existing range**: previously `lo` was set to `prev->second.end > va`, breaking `lo <= va <= hi` and allowing callers that clamp a window around `va` to underflow `end - start`. - **Return `0` from `title_overlap_end(lo, hi)` when `lo >= hi`**: empty/inverted half-open intervals `[lo, hi)` previously reported an overlap whenever `lo` lay inside a title memory range. - **Strong exception safety in `add()` and `add_title_memory()`**: pre-allocate the replacement `std::map` node via `extract()` before erasing overlapping entries, so `std::bad_alloc` never leaves `ranges_` / `memory_` partially erased or `count_` out of sync with `ranges_.size()`. ## Verification - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror -pedantic -fsanitize=undefined runtime/test/title_va_alias_test.cpp` -> exit 0, all checks pass, 0 warnings / 0 UBSan issues. - Mutation check against unpatched `main` (`git show main:runtime/src/title_va_alias.h` with updated `title_va_alias_test.cpp`) -> exit 1 (`!a.add(0, size, arena)` fails immediately; `gap()`, `title_overlap_end()`, and both `bad_alloc` checks also fail on unpatched `main`). - `python3 -I scripts/check_no_game_data.py runtime/src/title_va_alias.h runtime/test/title_va_alias_test.cpp` -> OK. - `python3 -m compileall -q make_game.py tools tests` and `python3 -I tests/test_text_write_line_endings.py` -> OK (3/3). - AI-assisted: yes - GPUs tested: none (CPU-only portable `title_va_alias_test`; no game files)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:01:21 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 08:44 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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 08:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1699#pullrequestreview-6054329016) · **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.
This pull request has changes conflicting with the target branch.
  • runtime/src/title_va_alias.h
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1699/head:github-bot/gh-1699'
git switch 'github-bot/gh-1699'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1699'
git switch 'github-bot/gh-1699'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1699'
git switch 'github-bot/gh-1699'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1699'
git switch 'main'
git merge --squash 'github-bot/gh-1699'
git switch 'main'
git merge --ff-only 'github-bot/gh-1699'
git switch 'main'
git merge 'github-bot/gh-1699'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.