[PR #928] cached_pso: guard null pointers, reject overlong keys, and add unit test #965

Open
opened 2026-11-26 20:19:38 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/928
Author: @narekshaghoyandev
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: ubiq-cached-pso-bounds


📝 Commits (2)

  • 977721c cached_pso: guard null pointers, reject overlong keys, and add unit test
  • 6e551a9 cached_pso: use valid empty span in test and drop unreachable null-span check

📊 Changes

3 files changed (+135 additions, -1 deletions)

View changed files

📝 runtime/CMakeLists.txt (+5 -0)
📝 runtime/src/cached_pso.h (+4 -1)
➕ runtime/test/cached_pso_test.cpp (+126 -0)

📄 Description

Summary

  • Guard null pointers in runtime/src/cached_pso.h:
    • fnv1a(nullptr, size) returns the initial FNV-1a offset basis instead of dereferencing NULL.
    • check() returns Check::invalid if blob.data() == nullptr.
    • KeyBuilder::tag(nullptr) encodes the null sentinel (0xffffffffu) instead of calling std::strlen(nullptr).
    • KeyBuilder::bytes(nullptr, n) treats null buffers as length 0 instead of reading through NULL.
  • Reject overlong keys (key.size() > key_bytes) in check() as Check::other_description instead of silently truncating them to 64 bytes and allowing distinct keys with a shared prefix to collide.
  • Add standalone C++20 unit test runtime/test/cached_pso_test.cpp (no GPU, no game data) and register cached_pso_test in runtime/CMakeLists.txt.

Verification

  • g++ -std=c++20 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -O1 -g runtime/test/cached_pso_test.cpp -o /tmp/cached_pso_test && /tmp/cached_pso_test — cached_pso_test: OK.
  • Negative control against main: crashes with AddressSanitizer: SEGV on null blob span before the patch and passes cleanly after.
  • python3 -I scripts/check_no_game_data.py runtime/src/cached_pso.h runtime/test/cached_pso_test.cpp runtime/CMakeLists.txt — clean.

Claimed in the coordination issue as: RT-CACHED-PSO-BOUNDS
AI-assisted: yes (Gemini)


🔄 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/928 **Author:** [@narekshaghoyandev](https://github.com/narekshaghoyandev) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `ubiq-cached-pso-bounds` --- ### 📝 Commits (2) - [`977721c`](https://github.com/ubiquitarianism/leonida/commit/977721c170318eab756bffd4dfcd07ca4d824dd6) cached_pso: guard null pointers, reject overlong keys, and add unit test - [`6e551a9`](https://github.com/ubiquitarianism/leonida/commit/6e551a9577ab1f7f2b18ea721c5c39996817e506) cached_pso: use valid empty span in test and drop unreachable null-span check ### 📊 Changes **3 files changed** (+135 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+5 -0) 📝 `runtime/src/cached_pso.h` (+4 -1) ➕ `runtime/test/cached_pso_test.cpp` (+126 -0) </details> ### 📄 Description ## Summary - Guard null pointers in `runtime/src/cached_pso.h`: - `fnv1a(nullptr, size)` returns the initial FNV-1a offset basis instead of dereferencing NULL. - `check()` returns `Check::invalid` if `blob.data() == nullptr`. - `KeyBuilder::tag(nullptr)` encodes the null sentinel (`0xffffffffu`) instead of calling `std::strlen(nullptr)`. - `KeyBuilder::bytes(nullptr, n)` treats null buffers as length 0 instead of reading through NULL. - Reject overlong keys (`key.size() > key_bytes`) in `check()` as `Check::other_description` instead of silently truncating them to 64 bytes and allowing distinct keys with a shared prefix to collide. - Add standalone C++20 unit test `runtime/test/cached_pso_test.cpp` (no GPU, no game data) and register `cached_pso_test` in `runtime/CMakeLists.txt`. ## Verification - `g++ -std=c++20 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -O1 -g runtime/test/cached_pso_test.cpp -o /tmp/cached_pso_test && /tmp/cached_pso_test` — `cached_pso_test: OK`. - Negative control against `main`: crashes with `AddressSanitizer: SEGV` on null blob span before the patch and passes cleanly after. - `python3 -I scripts/check_no_game_data.py runtime/src/cached_pso.h runtime/test/cached_pso_test.cpp runtime/CMakeLists.txt` — clean. Claimed in the coordination issue as: RT-CACHED-PSO-BOUNDS AI-assisted: yes (Gemini) --- <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#965
No description provided.