runtime: guard mesh_limit_refusal workgroup invocation product against uint64 overflow (RT-VULKAN-MESH-LIMITS-OVERFLOW) #1991

Open
github-bot wants to merge 1 commit from github-bot/gh-1991 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 17:34 UTC · original
IlyassRS3:fix/rt-vulkan-mesh-limits-overflow → main · +25 −2 · 2 files · 1 commits · open

Item ID: RT-VULKAN-MESH-LIMITS-OVERFLOW (claimed in #1608)

Summary

In mesh_limit_refusal() (runtime/src/vulkan_mesh_limits.h), the workgroup invocation check computed std::uint64_t(n[0]) * n[1] * n[2] > limits.maxMeshWorkGroupInvocations. Because n[0], n[1], and n[2] are 32-bit integers, their 3-way product can exceed 64 bits and wrap around in uint64_t (for example {1<<24, 1<<24, 1<<16} wraps to 0), allowing an oversized mesh workgroup to bypass the maxMeshWorkGroupInvocations refusal check.

  • Replace the 3-way multiplication with an overflow-free check (xy = uint64_t(n[0]) * n[1], then n[2] != 0 && (xy > limit || (xy != 0 && n[2] > limit / xy))), matching the division pattern used in subgroup_workgroup_fits() (runtime/src/subgroup_size.h).
  • Expand runtime/test/vulkan_mesh_limits_test.cpp with exact 3D invocation boundary, 2⁶⁴/2⁶⁶ wrap-around, UINT32_MAX boundary, and zero-limit tests.

Testing & Disclosure

  • AI-assisted: yes
  • GPUs tested: none (macOS host, CPU-only portable unit test)
  • clang++ -std=c++20 -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp: PASS
  • clang++ -std=c++20 -g -O1 -fsanitize=thread -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp: PASS
  • clang++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp: PASS
  • python3 -I scripts/check_no_game_data.py runtime/src/vulkan_mesh_limits.h runtime/test/vulkan_mesh_limits_test.cpp: PASS
  • python3 -I tests/test_text_write_line_endings.py: PASS (3/3)
**@⁠IlyassRS3** on GitHub · 2026-11-25 17:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1991) `IlyassRS3:fix/rt-vulkan-mesh-limits-overflow` → `main` · +25 −2 · 2 files · 1 commits · open Item ID: `RT-VULKAN-MESH-LIMITS-OVERFLOW` (claimed in #1608) ## Summary In `mesh_limit_refusal()` (`runtime/src/vulkan_mesh_limits.h`), the workgroup invocation check computed `std::uint64_t(n[0]) * n[1] * n[2] > limits.maxMeshWorkGroupInvocations`. Because `n[0]`, `n[1]`, and `n[2]` are 32-bit integers, their 3-way product can exceed 64 bits and wrap around in `uint64_t` (for example `{1<<24, 1<<24, 1<<16}` wraps to `0`), allowing an oversized mesh workgroup to bypass the `maxMeshWorkGroupInvocations` refusal check. - Replace the 3-way multiplication with an overflow-free check (`xy = uint64_t(n[0]) * n[1]`, then `n[2] != 0 && (xy > limit || (xy != 0 && n[2] > limit / xy))`), matching the division pattern used in `subgroup_workgroup_fits()` (`runtime/src/subgroup_size.h`). - Expand `runtime/test/vulkan_mesh_limits_test.cpp` with exact 3D invocation boundary, 2⁶⁴/2⁶⁶ wrap-around, `UINT32_MAX` boundary, and zero-limit tests. ## Testing & Disclosure - AI-assisted: yes - GPUs tested: none (macOS host, CPU-only portable unit test) - `clang++ -std=c++20 -g -O1 -fsanitize=address,undefined -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp`: PASS - `clang++ -std=c++20 -g -O1 -fsanitize=thread -fno-omit-frame-pointer -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp`: PASS - `clang++ -std=c++20 -O2 -Wall -Wextra -Werror -Wno-missing-field-initializers -I<vulkan-headers> runtime/test/vulkan_mesh_limits_test.cpp`: PASS - `python3 -I scripts/check_no_game_data.py runtime/src/vulkan_mesh_limits.h runtime/test/vulkan_mesh_limits_test.cpp`: PASS - `python3 -I tests/test_text_write_line_endings.py`: PASS (3/3)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:14:06 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 17:34 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 17:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1991#pullrequestreview-6062158518) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1991/head:github-bot/gh-1991'
git switch 'github-bot/gh-1991'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1991'
git switch 'github-bot/gh-1991'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1991'
git switch 'github-bot/gh-1991'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1991'
git switch 'main'
git merge --squash 'github-bot/gh-1991'
git switch 'main'
git merge --ff-only 'github-bot/gh-1991'
git switch 'main'
git merge 'github-bot/gh-1991'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.