[PR #486] [MERGED] SHADER-LIBRARY-BOUNDS-KEYS: guard zlib limit sums and reject malformed f16_halves keys #536

Closed
opened 2026-11-26 20:18:12 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/486
Author: @xroneyaa
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @QemmHD

Base: main ← Head: fix/shader-library-bounds-and-keys


📝 Commits (1)

  • 60905fe shader_library: guard zlib limit sums and reject malformed f16_halves keys

📊 Changes

2 files changed (+25 additions, -7 deletions)

View changed files

📝 runtime/src/shader_library.h (+17 -6)
📝 runtime/test/shader_library_test.cpp (+8 -1)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/486 **Author:** [@xroneyaa](https://github.com/xroneyaa) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/shader-library-bounds-and-keys` --- ### 📝 Commits (1) - [`60905fe`](https://github.com/ubiquitarianism/leonida/commit/60905fe78dbcf35da4a10950313dcea7eec05a74) shader_library: guard zlib limit sums and reject malformed f16_halves keys ### 📊 Changes **2 files changed** (+25 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/shader_library.h` (+17 -6) 📝 `runtime/test/shader_library_test.cpp` (+8 -1) </details> ### 📄 Description 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). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:12 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#536
No description provided.