[PR #2308] vulkan_device_markers: clamp memoryTypeCount, guard null proc/target and unmap #2312

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2308
Author: @narekshaghoyandev
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: ubiq-vulkan-device-markers-guards


📝 Commits (1)

  • 64da95c vulkan_device_markers: clamp memoryTypeCount, guard null proc/target and unmap

📊 Changes

2 files changed (+36 additions, -3 deletions)

View changed files

📝 runtime/src/vulkan_device_markers.h (+7 -2)
📝 runtime/test/vulkan_device_markers_test.cpp (+29 -1)

📄 Description

Fixes bounds, null-pointer, and teardown bugs in runtime/src/vulkan_device_markers.h:

  • Clamp memory.memoryTypeCount to VK_MAX_MEMORY_TYPES in DeviceMarkers::memory_type() so an oversized count cannot read past memory.memoryTypes[32] or shift 1u << i by >= 32.
  • Guard DeviceMarkers::create() against a null PFN_vkGetDeviceProcAddr loader pointer.
  • Guard MarkerTarget::started() / finished() against an empty target or null marker function pointers.
  • Only call vkUnmapMemory in ~DeviceMarkers() when words_ != nullptr (i.e. vkMapMemory succeeded), avoiding unmapping unmapped memory after a failed vkMapMemory.
  • Added regression tests in runtime/test/vulkan_device_markers_test.cpp.

Verification

  • g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Iruntime/src runtime/test/vulkan_device_markers_test.cpp passed
  • g++ -std=c++20 -fsanitize=address,undefined -Wall -Iruntime/src runtime/test/vulkan_device_markers_test.cpp passed
  • Negative control: new regression tests failed with UBSan OOB + shift-exponent-32 + ASan SEGV on unmodified ubiq/main
  • python3 -I scripts/check_no_game_data.py runtime/src/vulkan_device_markers.h runtime/test/vulkan_device_markers_test.cpp clean

Claimed in the coordination issue as: RT-VULKAN-DEVICE-MARKERS-BOUNDS-AND-UNMAP (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193601247)
AI-assisted: yes (Gemini)


🔄 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/2308 **Author:** [@narekshaghoyandev](https://github.com/narekshaghoyandev) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `ubiq-vulkan-device-markers-guards` --- ### 📝 Commits (1) - [`64da95c`](https://github.com/ubiquitarianism/leonida/commit/64da95c60e26dde57cae8d38dc515f3f16378bdd) vulkan_device_markers: clamp memoryTypeCount, guard null proc/target and unmap ### 📊 Changes **2 files changed** (+36 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan_device_markers.h` (+7 -2) 📝 `runtime/test/vulkan_device_markers_test.cpp` (+29 -1) </details> ### 📄 Description Fixes bounds, null-pointer, and teardown bugs in `runtime/src/vulkan_device_markers.h`: - Clamp `memory.memoryTypeCount` to `VK_MAX_MEMORY_TYPES` in `DeviceMarkers::memory_type()` so an oversized count cannot read past `memory.memoryTypes[32]` or shift `1u << i` by `>= 32`. - Guard `DeviceMarkers::create()` against a null `PFN_vkGetDeviceProcAddr` loader pointer. - Guard `MarkerTarget::started()` / `finished()` against an empty target or null marker function pointers. - Only call `vkUnmapMemory` in `~DeviceMarkers()` when `words_ != nullptr` (i.e. `vkMapMemory` succeeded), avoiding unmapping unmapped memory after a failed `vkMapMemory`. - Added regression tests in `runtime/test/vulkan_device_markers_test.cpp`. ### Verification - `g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Iruntime/src runtime/test/vulkan_device_markers_test.cpp` passed - `g++ -std=c++20 -fsanitize=address,undefined -Wall -Iruntime/src runtime/test/vulkan_device_markers_test.cpp` passed - Negative control: new regression tests failed with UBSan OOB + shift-exponent-32 + ASan SEGV on unmodified `ubiq/main` - `python3 -I scripts/check_no_game_data.py runtime/src/vulkan_device_markers.h runtime/test/vulkan_device_markers_test.cpp` clean Claimed in the coordination issue as: RT-VULKAN-DEVICE-MARKERS-BOUNDS-AND-UNMAP (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193601247) AI-assisted: yes (Gemini) --- <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#2312
No description provided.