SHADER-LIBRARY-BOUNDS-KEYS: guard zlib limit sums and reject malformed f16_halves keys #486
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!486
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/486/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@xroneyaa on GitHub · 2026-11-24 06:10 UTC · original
xroneyaa:fix/shader-library-bounds-and-keys→main· +25 −7 · 2 files · 1 commits · merged 2026-11-24 16:25 UTCClaimed in the coordination issue as: SHADER-LIBRARY-BOUNDS-KEYS
What and why
runtime/src/shader_library.h,detail::inflate_codesandzlib_inflatecheckedout.size() + length > limitandat + 4 > in.size(), which can overflowstd::size_twhenlimitis nearSIZE_MAX. Replaced these checks with overflow-free subtraction (out.size() > limit || length > limit - out.size(), andat > in.size() || in.size() - at < 4).ShaderLibrary::load_file()parsedf16_halvesJSON keys withstd::strtoul(key.c_str(), &end, 10), which accepted leading whitespace,+/-signs (e.g."-1"wrapping to0xFFFFFFFF), and truncated overflowing values like"4294967296"touint32_t(0)(overwriting parameter0). Replaced this with strict ASCII unsigned decimal parsing bounded toUINT32_MAX.Added
SIZE_MAXinflate tests and malformed/overflowingf16_halveskey rejection tests inruntime/test/shader_library_test.cpp.Tested
shader_library_testanddstorage_testwith MSVC 19.50 / Ninja (0 warnings in touched files)ctest --test-dir runtime/build -R "^(shader_library|dstorage)$" --output-on-failure-> 2/2 Passed (shader_library0.02 s,dstorage0.51 s)python -I scripts/check_no_game_data.py runtime/src/shader_library.h runtime/test/shader_library_test.cpp-> exit 0GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed (n/a — no translator rule added).@Oliwettoo on GitHub · 2026-11-24 10:39 UTC · original
Looks good. Built
shader_library_testwith g++ on Linux: it passes with the PR and fails againstmain's header at the newf16_halvescheck, so the stricter key parse is covered (strtoultook a leading-or space and truncated values past 32 bits). The rewritten limit and Adler-32 checks are overflow-safe forms of the old ones; without.size()never pastlimitthey only matter for alimitnearSIZE_MAX, so they're defensive. Ship. AI-assisted review.@QemmHD on GitHub · 2026-11-24 16:25 UTC · original
Merging.
Why merged: shader_library gets an overflow-safe zlib limit, Adler-32 checks and strict parsing of f16_halves keys, so malformed library input is refused instead of misread.
Why it's good: shader_library passes both plain and under validation.
Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Alone on main, its tests passed both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #388, #418, #421, #434, #470, #484, #485, #486 and #488 merged onto main
1504c1af6(a225e593e). There the repo-consistency set gives 566 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 306/308. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same skip set. git merge-tree against current main98a977b4b: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.AI-assisted (Claude Code, Claude Opus 5.5).