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

Open
opened 2026-11-26 21:18:42 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1699
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/title-va-alias-range-and-gap-guards


📝 Commits (1)

  • 0e3a9a4 title_va_alias: guard null add(), in-range gap(), empty title_overlap_end(), and bad_alloc

📊 Changes

2 files changed (+88 additions, -15 deletions)

View changed files

📝 runtime/src/title_va_alias.h (+30 -14)
📝 runtime/test/title_va_alias_test.cpp (+58 -1)

📄 Description

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)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1699 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/title-va-alias-range-and-gap-guards` --- ### 📝 Commits (1) - [`0e3a9a4`](https://github.com/ubiquitarianism/leonida/commit/0e3a9a412bd6799a67031c6b58688ca6244cc16b) title_va_alias: guard null add(), in-range gap(), empty title_overlap_end(), and bad_alloc ### 📊 Changes **2 files changed** (+88 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/title_va_alias.h` (+30 -14) 📝 `runtime/test/title_va_alias_test.cpp` (+58 -1) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1714
No description provided.