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

Closed
leonida/mandy
quietfold wants to merge 0 commits from fix/title-va-alias-range-and-gap-guards into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

quietfold commented 2026-11-25 08:44:00 +00:00

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)

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] reviewed 2026-11-25 08:44:15 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

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.

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.
Sign in to join this conversation.
No description provided.