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

Open
opened 2026-11-26 21:19:41 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1991
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-vulkan-mesh-limits-overflow


📝 Commits (1)

  • 7bfc32c runtime: guard mesh_limit_refusal workgroup invocation product against uint64 overflow

📊 Changes

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

View changed files

📝 runtime/src/vulkan_mesh_limits.h (+5 -2)
📝 runtime/test/vulkan_mesh_limits_test.cpp (+20 -0)

📄 Description

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)

🔄 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/1991 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-vulkan-mesh-limits-overflow` --- ### 📝 Commits (1) - [`7bfc32c`](https://github.com/ubiquitarianism/leonida/commit/7bfc32c0a77c94b0350a32461941539e832f378e) runtime: guard mesh_limit_refusal workgroup invocation product against uint64 overflow ### 📊 Changes **2 files changed** (+25 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan_mesh_limits.h` (+5 -2) 📝 `runtime/test/vulkan_mesh_limits_test.cpp` (+20 -0) </details> ### 📄 Description 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) --- <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#1998
No description provided.