Repository navigation
Conversation
SirKingg
left a comment
There was a problem hiding this comment.
Independent AI-assisted review. The current pipeline call sites produce 64-character SHA-256 keys and supply non-null data to KeyBuilder::bytes, so the synthetic collision cases below are not shown to be reachable from valid current PSO descriptions. They do leave the proposed malformed-input hardening incomplete; the new null-span test also has undefined behavior.
Windows/MSVC 19.44, Debug with /bigobj, RTX 4070 Ti, driver 32.0.16.1088: ctest --test-dir <build> -C Debug -R "^d3d12_(compute|draw)$" --output-on-failure -V passed 2/2; the compute test matched 11 cached-PSO responses on two host adapters. A separate synthetic MSVC probe reproduced the key and null-input collisions. The default Debug build first failed with C1128 before adding /bigobj. No game data used; no other GPUs or release build tested.
| if (get32(p + 8) != identity.vendor || get32(p + 12) != identity.device) return Check::other_adapter; | ||
| if (get32(p + 16) != identity.driver || std::memcmp(p + 20, identity.cache_uuid, 16) != 0) | ||
| return Check::other_driver; | ||
| if (key.size() > key_bytes) return Check::other_description; |
There was a problem hiding this comment.
This only checks the lookup key: encode(id, std::string(64, 'a') + "b") still truncates at resize, and check(id, std::string(64, 'a'), that_blob) returns accepted. Short keys also collide through zero padding (e.g. "a" and std::string("a\0", 2)). Please validate the encoding boundary too, or enforce the documented 64-character SHA-256 key invariant on both paths, and test the reverse direction. Current pipeline callers produce 64-character hex strings, so this is a malformed-key API issue rather than a demonstrated collision for valid PSOs.
| KeyBuilder& bytes(const void* p, std::size_t n) { | ||
| put32(data_, std::uint32_t(n)); | ||
| if (n) data_.insert(data_.end(), static_cast<const std::uint8_t*>(p), static_cast<const std::uint8_t*>(p) + n); | ||
| const std::size_t count = p ? n : 0; |
There was a problem hiding this comment.
bytes(nullptr, 16) now serializes exactly the same bytes as bytes(nullptr, 0), silently turning malformed data into an empty field instead of propagating an error. Similarly, fnv1a(nullptr, 16) returns the valid empty-input hash. This can make distinct descriptions indistinguishable if a caller supplies a missing nonempty field; can these APIs signal invalid input and have their callers propagate it rather than producing a usable key? Existing production bytes call sites currently pass non-null pointers.
| leonida::cached_pso::Check::invalid); | ||
| EXPECT(leonida::cached_pso::check( | ||
| test_id, valid_key, | ||
| std::span<const std::uint8_t>(static_cast<const std::uint8_t*>(nullptr), |
There was a problem hiding this comment.
Constructing a nonempty std::span from nullptr violates the constructor's valid-range precondition, so this test has undefined behavior before check is called; the !blob.data() guard cannot safely validate that case. MSVC here happened to return invalid even with STL hardening, but that does not make the construction valid. If null plus nonzero size needs to be rejected, validate a raw pointer and size before constructing the span and test that boundary instead.
…ter overload, and track invalid KeyBuilder inputs
|
Addressed all three points in commit
Re-verified on Windows 11 x64 (
AI-assisted (Gemini, Antigravity); no copyrighted game files or dumps used. |
|
Tested updated One integration detail worth checking: |
|
Tested
On @SirKingg's three points, from reading
Minor: there's an extra blank line before the closing namespace in |
Summary
Hardens
runtime/src/cached_pso.h(fnv1a,check,KeyBuilder) against null data pointers and key length truncation:check():key(key.empty()) withCheck::invalidso an uninitializedcache_key_never matches an all-zero key payload.Check::other_descriptionwhenkey.size() > key_bytes(64) instead of silently truncatingkeyviapadded.resize(key_bytes, '\0')(which caused any overlong key sharing a 64-byte prefix to returnCheck::accepted).fnv1a,check,KeyBuilder):fnv1a(const std::uint8_t* data, std::size_t size)against!datawhensize > 0.check()against!blob.data()when astd::spanis constructed withnullptrandblob_bytessize.KeyBuilder::tag(const char* name)againstname == nullptr(avoidingstd::strlen(nullptr)) andKeyBuilder::bytes(const void* p, std::size_t n)againstp == nullptr && n > 0.Hardware / Environment
10.0.26100)gfx1030, native wave64 subgroup 64), AMD driver26.11.2 / 2.0.353(32.0.21045.29003), Vulkan SDK1.4.363.119.52(VS2026 Build Tools + Ninja), Python3.15.2Verification
runtime/src/cached_pso.hedits):ctest --test-dir runtime/build -R "^d3d12_compute$" --output-on-failure -V->***Failedatline 427: leonida::cached_pso::check(test_id, valid_key + "b", encoded) == leonida::cached_pso::Check::other_descriptionruntime/src/cached_pso.hedits):ctest --test-dir runtime/build -R "^d3d12_compute$" --output-on-failure -V->1/1 Test #128: d3d12_compute Passedondevice: AMD Radeon RX 6900 XT(cached PSO: 2 host adapter(s) gave the same 11 answers)python -I -B tests/test_ci_registration.py->Ran 8 tests OKpython -I -B tests/test_text_write_line_endings.py->Ran 3 tests OKpython -I -B scripts/check_no_game_data.py-> exit0git diff --check-> exit0git merge-tree --write-tree upstream/main HEAD-> exit0AI-assisted (Gemini, Antigravity); no copyrighted game files or dumps used.