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

Closed
narekshaghoyandev wants to merge 2 commits from upstream-pr/928 into main
narekshaghoyandev commented 2026-11-24 15:14:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-24T15:14:35Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474908763 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/928). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-24T15:14:35Z. --- ## 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)
KernelSmoker commented 2026-11-24 15:16:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T15:16:15Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041977702 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/928#pullrequestreview-6041977702). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T15:16:15Z. **Review:** CHANGES_REQUESTED --- 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.
narekshaghoyandev commented 2026-11-24 15:20:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-24T15:20:04Z.


@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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7135848828 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/928#issuecomment-7135848828). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-24T15:20:04Z. --- @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).
KernelSmoker commented 2026-11-24 15:23:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T15:23:27Z.

Review: APPROVED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6042112660 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/928#pullrequestreview-6042112660). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T15:23:27Z. **Review:** APPROVED --- 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.
MoonEyes commented 2026-11-27 23:20:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:20:26Z.


Hi @narekshaghoyandev, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/CMakeLists.txt), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230064366 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/928#issuecomment-7230064366). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:20:26Z. --- Hi @narekshaghoyandev, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/CMakeLists.txt`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:32:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:32:31Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317777883 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/928#issuecomment-7317777883). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:32:31Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!928
No description provided.