SHADER-LIBRARY-BOUNDS-KEYS: guard zlib limit sums and reject malformed f16_halves keys #486

Manually merged
github merged 1 commit from gh-pr/486/head into gh-pr/486/base 2026-11-26 09:03:43 +00:00
Owner

@⁠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 UTC

Claimed in the coordination issue as: SHADER-LIBRARY-BOUNDS-KEYS

What and why

  1. In runtime/src/shader_library.h, detail::inflate_codes and zlib_inflate checked out.size() + length > limit and at + 4 > in.size(), which can overflow std::size_t when limit is near SIZE_MAX. Replaced these checks with overflow-free subtraction (out.size() > limit || length > limit - out.size(), and at > in.size() || in.size() - at < 4).
  2. ShaderLibrary::load_file() parsed f16_halves JSON keys with std::strtoul(key.c_str(), &end, 10), which accepted leading whitespace, +/- signs (e.g. "-1" wrapping to 0xFFFFFFFF), and truncated overflowing values like "4294967296" to uint32_t(0) (overwriting parameter 0). Replaced this with strict ASCII unsigned decimal parsing bounded to UINT32_MAX.

Added SIZE_MAX inflate tests and malformed/overflowing f16_halves key rejection tests in runtime/test/shader_library_test.cpp.

Tested

  • Rebuilt shader_library_test and dstorage_test with 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_library 0.02 s, dstorage 0.51 s)
  • python -I scripts/check_no_game_data.py runtime/src/shader_library.h runtime/test/shader_library_test.cpp -> exit 0

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed (n/a — no translator rule added).
**@⁠xroneyaa** on GitHub · 2026-11-24 06:10 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/486) `xroneyaa:fix/shader-library-bounds-and-keys` → `main` · +25 −7 · 2 files · 1 commits · merged 2026-11-24 16:25 UTC Claimed in the coordination issue as: SHADER-LIBRARY-BOUNDS-KEYS ### What and why 1. In `runtime/src/shader_library.h`, `detail::inflate_codes` and `zlib_inflate` checked `out.size() + length > limit` and `at + 4 > in.size()`, which can overflow `std::size_t` when `limit` is near `SIZE_MAX`. Replaced these checks with overflow-free subtraction (`out.size() > limit || length > limit - out.size()`, and `at > in.size() || in.size() - at < 4`). 2. `ShaderLibrary::load_file()` parsed `f16_halves` JSON keys with `std::strtoul(key.c_str(), &end, 10)`, which accepted leading whitespace, `+`/`-` signs (e.g. `"-1"` wrapping to `0xFFFFFFFF`), and truncated overflowing values like `"4294967296"` to `uint32_t(0)` (overwriting parameter `0`). Replaced this with strict ASCII unsigned decimal parsing bounded to `UINT32_MAX`. Added `SIZE_MAX` inflate tests and malformed/overflowing `f16_halves` key rejection tests in `runtime/test/shader_library_test.cpp`. ### Tested - Rebuilt `shader_library_test` and `dstorage_test` with 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_library` 0.02 s, `dstorage` 0.51 s) - `python -I scripts/check_no_game_data.py runtime/src/shader_library.h runtime/test/shader_library_test.cpp` -> exit 0 GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed (n/a — no translator rule added).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:03:38 +00:00
github manually merged commit 60905fe78d into gh-pr/486/base 2026-11-26 09:03:43 +00:00
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-24 10:39 UTC · original

Looks good. Built shader_library_test with g++ on Linux: it passes with the PR and fails against main's header at the new f16_halves check, so the stricter key parse is covered (strtoul took 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; with out.size() never past limit they only matter for a limit near SIZE_MAX, so they're defensive. Ship. AI-assisted review.

**@⁠Oliwettoo** on GitHub · 2026-11-24 10:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/486#issuecomment-7129064404) Looks good. Built `shader_library_test` with g++ on Linux: it passes with the PR and fails against `main`'s header at the new `f16_halves` check, so the stricter key parse is covered (`strtoul` took 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; with `out.size()` never past `limit` they only matter for a `limit` near `SIZE_MAX`, so they're defensive. Ship. AI-assisted review.
Author
Owner

@⁠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 main 98a977b4b: 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).

**@⁠QemmHD** on GitHub · 2026-11-24 16:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/486#issuecomment-7137646205) 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 main 98a977b4b: 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.