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

Closed
leonida/mandy
narekshaghoyandev wants to merge 0 commits from ubiq-cached-pso-bounds into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

narekshaghoyandev commented 2026-11-24 15:14:35 +00:00

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)

## 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 reviewed 2026-11-24 15:16:15 +00:00
KernelSmoker left a comment
No description provided.
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

@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 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 approved these changes 2026-11-24 15:23:27 +00:00
KernelSmoker left a comment

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.

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

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

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

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.

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.
Sign in to join this conversation.
No description provided.