cached_pso: guard null pointers, reject overlong keys, and add unit test #928

Open
github-bot wants to merge 2 commits from github-bot/gh-928 into main AGit
Owner

@⁠narekshaghoyandev on GitHub · 2026-11-24 15:14 UTC · original
narekshaghoyandev:ubiq-cached-pso-bounds → main · +135 −1 · 3 files · 2 commits · open

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)

**@⁠narekshaghoyandev** on GitHub · 2026-11-24 15:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/928) `narekshaghoyandev:ubiq-cached-pso-bounds` → `main` · +135 −1 · 3 files · 2 commits · open ## 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:28:46 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 15:16 UTC · original · requested changes

Reviewed exact head 977721c170318eab756bffd4dfcd07ca4d824dd6. The standalone test passes in the default build, but its null-blob case constructs std::span<const uint8_t>(nullptr, blob_bytes). A non-empty span requires a valid contiguous range, so this constructor violates the span precondition before check() can inspect data(). I reproduced the test abort with g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic ...; libstdc++ reports an invalid iterator range. Please remove this invalid construction and the unreachable non-empty-null-span check (or cover only a valid empty span, which is already rejected by the size guard). Verification: the normal targeted binary prints OK; _GLIBCXX_DEBUG aborts on the invalid span as described. No game data or GPU used.

**@⁠KernelSmoker** on GitHub · 2026-11-24 15:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/928#pullrequestreview-6041977702) · **requested changes** Reviewed exact head `977721c170318eab756bffd4dfcd07ca4d824dd6`. The standalone test passes in the default build, but its null-blob case constructs `std::span<const uint8_t>(nullptr, blob_bytes)`. A non-empty span requires a valid contiguous range, so this constructor violates the span precondition before `check()` can inspect `data()`. I reproduced the test abort with `g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic ...`; libstdc++ reports an invalid iterator range. Please remove this invalid construction and the unreachable non-empty-null-span check (or cover only a valid empty span, which is already rejected by the size guard). Verification: the normal targeted binary prints OK; `_GLIBCXX_DEBUG` aborts on the invalid span as described. No game data or GPU used.
Author
Owner

@⁠narekshaghoyandev on GitHub · 2026-11-24 15:20 UTC · original

@⁠KernelSmoker Good catch — fixed in 6e551a957:

  • Removed the invalid std::span(nullptr, blob_bytes) construction from runtime/test/cached_pso_test.cpp and replaced it with a valid empty std::span<const std::uint8_t>{}.
  • Removed the unreachable blob.data() == nullptr branch from cached_pso::check().

Re-verified with both:

  • g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic -O1 -g runtime/test/cached_pso_test.cpp -> cached_pso_test: OK
  • g++ -std=c++20 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -O1 -g runtime/test/cached_pso_test.cpp -> cached_pso_test: OK
  • Negative control against main fails on overlong_key check and fnv1a(nullptr, 16).

AI-assisted (Gemini).

**@⁠narekshaghoyandev** on GitHub · 2026-11-24 15:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/928#issuecomment-7135848828) @⁠KernelSmoker Good catch — fixed in `6e551a957`: - Removed the invalid `std::span(nullptr, blob_bytes)` construction from `runtime/test/cached_pso_test.cpp` and replaced it with a valid empty `std::span<const std::uint8_t>{}`. - Removed the unreachable `blob.data() == nullptr` branch from `cached_pso::check()`. Re-verified with both: - `g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic -O1 -g runtime/test/cached_pso_test.cpp` -> `cached_pso_test: OK` - `g++ -std=c++20 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -O1 -g runtime/test/cached_pso_test.cpp` -> `cached_pso_test: OK` - Negative control against `main` fails on `overlong_key` check and `fnv1a(nullptr, 16)`. AI-assisted (Gemini).
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 15:23 UTC · original · approved these changes

Retested corrected exact head 6e551a9577ab1f7f2b18ea721c5c39996817e506. The invalid non-empty null span and unreachable blob.data()==nullptr check are gone; the valid empty-span case is rejected by the size guard. Both the normal GCC build and -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic -O1 -g build of runtime/test/cached_pso_test.cpp pass (cached_pso_test: OK). Diff check passes. I did not independently run ASan/UBSan because the available host/tool container lacks sanitizer runtimes. No game data/GPU used.

**@⁠KernelSmoker** on GitHub · 2026-11-24 15:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/928#pullrequestreview-6042112660) · **approved these changes** Retested corrected exact head `6e551a9577ab1f7f2b18ea721c5c39996817e506`. The invalid non-empty null span and unreachable `blob.data()==nullptr` check are gone; the valid empty-span case is rejected by the size guard. Both the normal GCC build and `-D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic -O1 -g` build of `runtime/test/cached_pso_test.cpp` pass (`cached_pso_test: OK`). Diff check passes. I did not independently run ASan/UBSan because the available host/tool container lacks sanitizer runtimes. No game data/GPU used.
This pull request has changes conflicting with the target branch.
  • runtime/CMakeLists.txt
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/928/head:github-bot/gh-928'
git switch 'github-bot/gh-928'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-928'
git switch 'github-bot/gh-928'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-928'
git switch 'github-bot/gh-928'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-928'
git switch 'main'
git merge --squash 'github-bot/gh-928'
git switch 'main'
git merge --ff-only 'github-bot/gh-928'
git switch 'main'
git merge 'github-bot/gh-928'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.