[PR #1739] runtime: guard DescriptorTable 9-way collision, read_slots width, and change-tracking OOM #1751

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

📋 Pull Request Information

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

Base: main ← Head: fix/descriptor-table-guards


📝 Commits (1)

  • f41be19 runtime: guard DescriptorTable 9-way collision, read_slots width, and change-tracking OOM

📊 Changes

2 files changed (+187 additions, -12 deletions)

View changed files

📝 runtime/src/descriptor_table.h (+24 -12)
📝 runtime/test/descriptor_table_test.cpp (+163 -0)

📄 Description

Item ID: RT-DESCRIPTOR-TABLE-GUARDS
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159904197

Summary

Hardens runtime/src/descriptor_table.h (the bindless set 0, binding 2 T#/S# hash table) against three edge-case bugs:

  1. Unresolvable 9-way full-hash collision checked before load-factor growth (insert_locked()): previously, (occupied_count_ + 1) * 2 > entries_.size() called grow_locked() before checking whether all 8 probe slots already held keys with full hash h. Inserting a 9th colliding key into a 16-slot table needlessly doubled capacity (16 -> 32) and set all_changed_ = true before throwing std::length_error. Checking the 8-slot full-hash collision first refuses immediately without mutating capacity or dirty state.
  2. 64-bit slot offset arithmetic in read_slots(): widened dest + std::size_t(i) * 10 and entries_[std::size_t(first) + i] so large counts cannot wrap 32-bit uint32_t arithmetic.
  3. Strong exception safety for dirty-slot tracking & skip redundant tracking under all_changed_:
    • Previously mark(slot) pushed to changed_slots_ after mutating entries_ and occupied_count_ (and before --occupied_count_ in erase_locked()). A std::bad_alloc inside changed_slots_.push_back left CPU entries mutated (and occupied_count_ stale on erase) while dropping the dirty slot from take_changes(), desynchronizing the GPU descriptor table from the CPU table.
    • reserve_marks(count) now reserves changed_slots_ capacity before mutating entries_/occupied_count_ (and before make_probe_slot() relocates a resident), and both reserve_marks() and mark() are no-ops when all_changed_ is already set (since the next BindlessSet upload writes the full table).

Verification

  • AI-assisted: yes
  • GPUs tested: none (portable CPU-only C++20 header and unit test)
  • Commands run (macOS, Apple Clang, C++20):
    • clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=undefined runtime/test/descriptor_table_test.cpp -pthread: PASS (0 failures).
    • clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/descriptor_table_test.cpp -pthread: PASS (0 failures).
    • Mutation test running the updated descriptor_table_test.cpp against unpatched main:runtime/src/descriptor_table.h: FAILS as expected (exit 1 on test_unresolvable_collision_does_not_grow_at_load_threshold).
    • python3 -I scripts/check_no_game_data.py runtime/src/descriptor_table.h runtime/test/descriptor_table_test.cpp: PASS.
    • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.

🔄 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/1739 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/descriptor-table-guards` --- ### 📝 Commits (1) - [`f41be19`](https://github.com/ubiquitarianism/leonida/commit/f41be1995c28228237e6bc6f9c03eed458c4ae78) runtime: guard DescriptorTable 9-way collision, read_slots width, and change-tracking OOM ### 📊 Changes **2 files changed** (+187 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/descriptor_table.h` (+24 -12) 📝 `runtime/test/descriptor_table_test.cpp` (+163 -0) </details> ### 📄 Description Item ID: `RT-DESCRIPTOR-TABLE-GUARDS` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7159904197 ## Summary Hardens `runtime/src/descriptor_table.h` (the bindless set 0, binding 2 T#/S# hash table) against three edge-case bugs: 1. **Unresolvable 9-way full-hash collision checked before load-factor growth** (`insert_locked()`): previously, `(occupied_count_ + 1) * 2 > entries_.size()` called `grow_locked()` before checking whether all 8 probe slots already held keys with full hash `h`. Inserting a 9th colliding key into a 16-slot table needlessly doubled capacity (`16 -> 32`) and set `all_changed_ = true` before throwing `std::length_error`. Checking the 8-slot full-hash collision first refuses immediately without mutating capacity or dirty state. 2. **64-bit slot offset arithmetic in `read_slots()`**: widened `dest + std::size_t(i) * 10` and `entries_[std::size_t(first) + i]` so large counts cannot wrap 32-bit `uint32_t` arithmetic. 3. **Strong exception safety for dirty-slot tracking & skip redundant tracking under `all_changed_`**: - Previously `mark(slot)` pushed to `changed_slots_` *after* mutating `entries_` and `occupied_count_` (and before `--occupied_count_` in `erase_locked()`). A `std::bad_alloc` inside `changed_slots_.push_back` left CPU entries mutated (and `occupied_count_` stale on erase) while dropping the dirty slot from `take_changes()`, desynchronizing the GPU descriptor table from the CPU table. - `reserve_marks(count)` now reserves `changed_slots_` capacity before mutating `entries_`/`occupied_count_` (and before `make_probe_slot()` relocates a resident), and both `reserve_marks()` and `mark()` are no-ops when `all_changed_` is already set (since the next `BindlessSet` upload writes the full table). ## Verification - **AI-assisted**: yes - **GPUs tested**: none (portable CPU-only C++20 header and unit test) - **Commands run** (macOS, Apple Clang, C++20): - `clang++ -std=c++20 -Wall -Wextra -Werror -O1 -g -fsanitize=undefined runtime/test/descriptor_table_test.cpp -pthread`: **PASS** (`0 failures`). - `clang++ -std=c++20 -Wall -Wextra -Werror -O2 runtime/test/descriptor_table_test.cpp -pthread`: **PASS** (`0 failures`). - Mutation test running the updated `descriptor_table_test.cpp` against unpatched `main:runtime/src/descriptor_table.h`: **FAILS as expected** (`exit 1` on `test_unresolvable_collision_does_not_grow_at_load_threshold`). - `python3 -I scripts/check_no_game_data.py runtime/src/descriptor_table.h runtime/test/descriptor_table_test.cpp`: **PASS**. - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. --- <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#1751
No description provided.