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

Closed
IlyassRS3 wants to merge 1 commit from upstream-pr/1699 into main
IlyassRS3 commented 2026-11-25 08:44:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T08:44:00Z.


Item ID: TITLE-VA-ALIAS-RANGE-AND-GAP-GUARDS
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157362802

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)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5488013621 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1699). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T08:44:00Z. --- Item ID: `TITLE-VA-ALIAS-RANGE-AND-GAP-GUARDS` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7157362802 ## 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)
copilot-pull-request-reviewer[bot] commented 2026-11-25 08:44:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T08:44:15Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6054329016 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1699#pullrequestreview-6054329016). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T08:44:15Z. **Review:** COMMENTED --- 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.
aslan2142 commented 2026-12-01 16:37:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:37:18Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317909117 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1699#issuecomment-7317909117). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:37:18Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1699
No description provided.