DEPTH24-SCRATCH-BOUNDS-OVERFLOW: guard integer overflows in Depth24Converter #524

Closed
github-bot wants to merge 1 commit from github-bot/gh-524 into main AGit
Owner

@⁠xroneyaa on GitHub · 2026-11-24 06:55 UTC · original
fix/depth24-scratch-bounds-overflow → main · +520 −28 · 3 files · 1 commits · closed without merging

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).
**@⁠xroneyaa** on GitHub · 2026-11-24 06:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/524) `fix/depth24-scratch-bounds-overflow` → `main` · +520 −28 · 3 files · 1 commits · closed without merging 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:05:54 +00:00
Author
Owner

@⁠Sangonapou on GitHub · 2026-11-24 19:07 UTC · original

Tested 00523443 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass

Built at this head with scripts\build_runtime.ps1 (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files.

ctest -R ^depth24_bounds$ -V: passed, depth24_bounds: all checks passed.

**@⁠Sangonapou** on GitHub · 2026-11-24 19:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/524#issuecomment-7141639433) Tested 00523443 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass Built at this head with `scripts\build_runtime.ps1` (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files. `ctest -R ^depth24_bounds$ -V`: passed, `depth24_bounds: all checks passed`.
github-bot closed this pull request 2026-11-27 07:40:10 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.