[PR #524] DEPTH24-SCRATCH-BOUNDS-OVERFLOW: guard integer overflows in Depth24Converter #571

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/524
Author: @xroneyaa
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/depth24-scratch-bounds-overflow


📝 Commits (1)

  • 0052344 depth24: guard integer overflows in Depth24Converter prepare, scratch, and run

📊 Changes

3 files changed (+520 additions, -28 deletions)

View changed files

📝 runtime/CMakeLists.txt (+9 -0)
📝 runtime/src/vulkan_depth24.h (+62 -28)
➕ runtime/test/depth24_bounds_test.cpp (+449 -0)

📄 Description

Claimed in the coordination issue as: DEPTH24-SCRATCH-BOUNDS-OVERFLOW

What and why

Depth24Converter in runtime/src/vulkan_depth24.h had several integer-overflow and pre-validation gaps:

  1. prepare():
    • whole.app_offset > whole.app_size was not checked before whole.app_offset + span_words * 4 > whole.app_size, so an offset near UINT64_MAX could wrap past 0 and pass bounds validation.
    • (s - 1) * whole.app_slice_words + (h - 1) * whole.app_row_words + aw, span_words * 4, sw * h * s * 4, and max_range_ part sizing (* 4 + slack) used unchecked 64-bit arithmetic.
    • make_pipeline() and scratch(...) ran before checking max_range_, so an oversized row or max_range_ <= 256 left an unused scratch buffer allocation in current_.chunks.
    • Caller-provided whole.scratch did not validate scratch_offset % 4 == 0 or overflow of whole.scratch_offset + total_scratch_bytes.
  2. scratch():
    • (chunk.used + alignment - 1) / alignment * alignment wrapped uint64_t near UINT64_MAX, and start + bytes <= chunk.size wrapped when bytes was near UINT64_MAX.
  3. make_part():
    • window + range and part.app_offset - window + span were unchecked.
  4. run():
    • (job.width + 7) / 8 and (job.height + 7) / 8 wrapped uint32_t near UINT32_MAX.

This adds checked_add / checked_mul guards and O(1) overflow-free part sizing in prepare(), pre-validates everything before pipeline creation or scratch allocation, uses overflow-free alignment padding in scratch(), guards make_part() range checks, promotes job.width/job.height in run(), and adds the CPU-only mock-Vulkan test runtime/test/depth24_bounds_test.cpp (depth24_bounds).

Tested

  • Rebuilt depth24_bounds_test and depth24_convert_test with MSVC 19.50 / Ninja (0 warnings under /W4)
  • ctest --test-dir runtime/build --output-on-failure -R "^(depth24_bounds|depth24_convert)$" (VK_LOADER_LAYERS_DISABLE=~implicit~) -> 2/2 Passed (depth24_convert 5.00 s on RTX 3060 Ti, depth24_bounds 0.01 s CPU-only)
  • python -I scripts/check_no_game_data.py runtime/src/vulkan_depth24.h runtime/test/depth24_bounds_test.cpp runtime/CMakeLists.txt -> exit 0

GPUs tested: NVIDIA GeForce RTX 3060 Ti (depth24_convert 1/1 Passed; depth24_bounds CPU-only)

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/524 **Author:** [@xroneyaa](https://github.com/xroneyaa) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/depth24-scratch-bounds-overflow` --- ### 📝 Commits (1) - [`0052344`](https://github.com/ubiquitarianism/leonida/commit/00523443475c1a9f75ed927367445013f74cb5b4) depth24: guard integer overflows in Depth24Converter prepare, scratch, and run ### 📊 Changes **3 files changed** (+520 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+9 -0) 📝 `runtime/src/vulkan_depth24.h` (+62 -28) ➕ `runtime/test/depth24_bounds_test.cpp` (+449 -0) </details> ### 📄 Description Claimed in the coordination issue as: DEPTH24-SCRATCH-BOUNDS-OVERFLOW ### What and why `Depth24Converter` in `runtime/src/vulkan_depth24.h` had several integer-overflow and pre-validation gaps: 1. `prepare()`: - `whole.app_offset > whole.app_size` was not checked before `whole.app_offset + span_words * 4 > whole.app_size`, so an offset near `UINT64_MAX` could wrap past `0` and pass bounds validation. - `(s - 1) * whole.app_slice_words + (h - 1) * whole.app_row_words + aw`, `span_words * 4`, `sw * h * s * 4`, and `max_range_` part sizing (`* 4 + slack`) used unchecked 64-bit arithmetic. - `make_pipeline()` and `scratch(...)` ran before checking `max_range_`, so an oversized row or `max_range_ <= 256` left an unused scratch buffer allocation in `current_.chunks`. - Caller-provided `whole.scratch` did not validate `scratch_offset % 4 == 0` or overflow of `whole.scratch_offset + total_scratch_bytes`. 2. `scratch()`: - `(chunk.used + alignment - 1) / alignment * alignment` wrapped `uint64_t` near `UINT64_MAX`, and `start + bytes <= chunk.size` wrapped when `bytes` was near `UINT64_MAX`. 3. `make_part()`: - `window + range` and `part.app_offset - window + span` were unchecked. 4. `run()`: - `(job.width + 7) / 8` and `(job.height + 7) / 8` wrapped `uint32_t` near `UINT32_MAX`. This adds `checked_add` / `checked_mul` guards and O(1) overflow-free part sizing in `prepare()`, pre-validates everything before pipeline creation or scratch allocation, uses overflow-free alignment padding in `scratch()`, guards `make_part()` range checks, promotes `job.width`/`job.height` in `run()`, and adds the CPU-only mock-Vulkan test `runtime/test/depth24_bounds_test.cpp` (`depth24_bounds`). ### Tested - Rebuilt `depth24_bounds_test` and `depth24_convert_test` with MSVC 19.50 / Ninja (0 warnings under `/W4`) - `ctest --test-dir runtime/build --output-on-failure -R "^(depth24_bounds|depth24_convert)$"` (`VK_LOADER_LAYERS_DISABLE=~implicit~`) -> 2/2 Passed (`depth24_convert` 5.00 s on RTX 3060 Ti, `depth24_bounds` 0.01 s CPU-only) - `python -I scripts/check_no_game_data.py runtime/src/vulkan_depth24.h runtime/test/depth24_bounds_test.cpp runtime/CMakeLists.txt` -> exit 0 GPUs tested: NVIDIA GeForce RTX 3060 Ti (`depth24_convert` 1/1 Passed; `depth24_bounds` CPU-only) 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>
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#571
No description provided.