d3d12_title_image_census: guard null entries/resources and use stable_sort #2331

Merged
leonida/mandy
narekshaghoyandev merged 1 commit from ubiq-title-image-census-guards into main 2026-11-29 14:26:09 +00:00

Pull request successfully merged and closed

narekshaghoyandev commented 2026-11-26 13:57:14 +00:00

Fixes null-pointer dereferences and non-deterministic tie-breaking in rt::d3d12::log_title_image_uses() (runtime/shims/d3d12_title_image_census.h):

  • Skip null registry entries (!t) in both passes over textures before dereferencing t->owned / t->cpu.
  • Guard !t->resource before dereferencing t->resource->desc() for placed entries.
  • Use std::stable_sort instead of std::sort when ranking classes (copied from an ordered std::map<Shape, AllocationClass>) so equal-sized shapes break ties deterministically.
  • Added standalone unit test runtime/test/d3d12_title_image_census_test.cpp.

Verification

  • g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic runtime/test/d3d12_title_image_census_test.cpp passed
  • g++ -std=c++20 -fsanitize=address,undefined -Wall -Wextra -Werror -pedantic runtime/test/d3d12_title_image_census_test.cpp passed
  • Negative control: new test failed with UBSan null-member-access + ASan SEGV against unmodified ubiq/main
  • python3 -I scripts/check_no_game_data.py runtime/shims/d3d12_title_image_census.h runtime/test/d3d12_title_image_census_test.cpp clean

Claimed in the coordination issue as: RT-TITLE-IMAGE-CENSUS-NULL-GUARDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194035099)
AI-assisted: yes (Gemini)

Fixes null-pointer dereferences and non-deterministic tie-breaking in `rt::d3d12::log_title_image_uses()` (`runtime/shims/d3d12_title_image_census.h`): - Skip null registry entries (`!t`) in both passes over `textures` before dereferencing `t->owned` / `t->cpu`. - Guard `!t->resource` before dereferencing `t->resource->desc()` for placed entries. - Use `std::stable_sort` instead of `std::sort` when ranking `classes` (copied from an ordered `std::map<Shape, AllocationClass>`) so equal-sized shapes break ties deterministically. - Added standalone unit test `runtime/test/d3d12_title_image_census_test.cpp`. ### Verification - `g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic runtime/test/d3d12_title_image_census_test.cpp` passed - `g++ -std=c++20 -fsanitize=address,undefined -Wall -Wextra -Werror -pedantic runtime/test/d3d12_title_image_census_test.cpp` passed - Negative control: new test failed with UBSan null-member-access + ASan SEGV against unmodified `ubiq/main` - `python3 -I scripts/check_no_game_data.py runtime/shims/d3d12_title_image_census.h runtime/test/d3d12_title_image_census_test.cpp` clean Claimed in the coordination issue as: RT-TITLE-IMAGE-CENSUS-NULL-GUARDS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194035099) AI-assisted: yes (Gemini)
lixonik reviewed 2026-11-26 15:40:36 +00:00
lixonik left a comment
No description provided.
Ran `d3d12_title_image_census_test.cpp` directly with GCC 11 and UBSan on Ubuntu/WSL. The synthetic census passed without sanitizer findings. Could the new source also be registered with CTest? It currently has no build/test entry. AI-assisted.
zmasi commented 2026-11-28 12:02:34 +00:00

VERIFY-2331-D3D12 — verified head d11cbcc1f5 merged cleanly with main 030d2039e on Windows 11 Pro (build 26200), MSVC 19.44 (x64, /std:c++20 /W4 /WX /permissive- /utf-8 /EHsc), synthetic registry entries only.

Red (main 030d2039e) -> Green (030d2039e + d11cbcc1f5)

  • Red on main:
    • Compiling and running runtime/test/d3d12_title_image_census_test.cpp against main's runtime/shims/d3d12_title_image_census.h -> crashed with 0xC0000005 (STATUS_ACCESS_VIOLATION) dereferencing t->owned on the null registry entry (textures.emplace(2, nullptr)).
  • Green on merged PR:
    • cl.exe /nologo /std:c++20 /W4 /WX /permissive- /utf-8 /EHsc runtime/test/d3d12_title_image_census_test.cpp -> 0 warnings, exit 0 (d3d12_title_image_census_test: ok, reporting 1 slot-70 images sharing slot-133 base 2.0 MiB and 1 retired awaiting release 1.0 MiB without dereferencing null entries or null t->resource).

AI-assisted.

`VERIFY-2331-D3D12` — verified head `d11cbcc1f5` merged cleanly with `main` `030d2039e` on Windows 11 Pro (build 26200), MSVC `19.44` (`x64`, `/std:c++20 /W4 /WX /permissive- /utf-8 /EHsc`), synthetic registry entries only. ### Red (`main` `030d2039e`) -> Green (`030d2039e` + `d11cbcc1f5`) - **Red on `main`**: - Compiling and running `runtime/test/d3d12_title_image_census_test.cpp` against `main`'s `runtime/shims/d3d12_title_image_census.h` -> crashed with **`0xC0000005` (`STATUS_ACCESS_VIOLATION`)** dereferencing `t->owned` on the null registry entry (`textures.emplace(2, nullptr)`). - **Green on merged PR**: - `cl.exe /nologo /std:c++20 /W4 /WX /permissive- /utf-8 /EHsc runtime/test/d3d12_title_image_census_test.cpp` -> **0 warnings**, exit **`0`** (`d3d12_title_image_census_test: ok`, reporting `1 slot-70 images sharing slot-133 base 2.0 MiB` and `1 retired awaiting release 1.0 MiB` without dereferencing null entries or null `t->resource`). AI-assisted.
OreoFR commented 2026-11-28 22:02:09 +00:00

Verified by OreoFR

  • Base: main c1ecf04ed + PR head d11cbcc1f; green run in a merge package of 16 PRs, no new ctest failure vs main
  • Test: standalone build of d3d12_title_image_census_test.exe (the test is not registered in CMake)
  • Red on main: crash 0xC0000005 (null entry)
  • Green with the PR: OK
  • Verdict: READY (the test is not in CMake: ctest will never run it)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `d11cbcc1f`; green run in a merge package of 16 PRs, no new ctest failure vs main - Test: `standalone build of d3d12_title_image_census_test.exe (the test is not registered in CMake)` - Red on main: crash 0xC0000005 (null entry) - Green with the PR: OK - Verdict: READY (the test is not in CMake: ctest will never run it) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
TheGeogeo commented 2026-11-28 22:49:49 +00:00

Tested d11cbcc1f merged (no commit) with main aa918e5d9, MSVC 19.52 (Visual Studio 18), Windows 11 10.0.26300.

Blocker: runtime/test/d3d12_title_image_census_test.cpp is new but is not registered in runtime/CMakeLists.txt, so neither CI nor ctest ever builds or runs it. ctest -N on the merge lists no such test, and tests/test_ctest_registration.py still passes, so nothing catches this. Registering it the way the other header-only tests are would fix that:

add_executable(d3d12_title_image_census_test test/d3d12_title_image_census_test.cpp)
add_test(NAME d3d12_title_image_census COMMAND d3d12_title_image_census_test)

Hand-compiled (cl /std:c++20 /EHsc /O2):

  • Green: exit 0.
  • Red, with runtime/shims/d3d12_title_image_census.h back to main: crash, exit 0xC0000005.

I did not run the ctest tests relinked by the header change: test runs on this machine are paused for memory.

AI-assisted (Claude Code).

Tested `d11cbcc1f` merged (no commit) with `main` `aa918e5d9`, MSVC 19.52 (Visual Studio 18), Windows 11 10.0.26300. **Blocker:** `runtime/test/d3d12_title_image_census_test.cpp` is new but is not registered in `runtime/CMakeLists.txt`, so neither CI nor `ctest` ever builds or runs it. `ctest -N` on the merge lists no such test, and `tests/test_ctest_registration.py` still passes, so nothing catches this. Registering it the way the other header-only tests are would fix that: ```cmake add_executable(d3d12_title_image_census_test test/d3d12_title_image_census_test.cpp) add_test(NAME d3d12_title_image_census COMMAND d3d12_title_image_census_test) ``` Hand-compiled (`cl /std:c++20 /EHsc /O2`): - Green: exit 0. - Red, with `runtime/shims/d3d12_title_image_census.h` back to `main`: crash, exit `0xC0000005`. I did not run the ctest tests relinked by the header change: test runs on this machine are paused for memory. AI-assisted (Claude Code).
timbot103 reviewed 2026-11-29 04:27:52 +00:00
timbot103 left a comment
No description provided.
Static audit of `d11cbcc1f` only, with no builds or GPU runs. Both passes in `runtime/shims/d3d12_title_image_census.h` now guard null registry pointers, and the placed-resource guard precedes every resource dereference in the helper. The comparator uses `>` on unsigned byte totals, which gives a strict weak ordering even if a sum wraps. `std::stable_sort` preserves `std::map` shape order for equal keys. The fixture uses standard C++20 facilities, and the PR discussion reports standalone GCC and MSVC runs. - `runtime/test/d3d12_title_image_census_test.cpp:45` — Please add the executable and its `add_test` entry in the portable section of `runtime/CMakeLists.txt`. The runtime CI jobs currently omit this regression from their CMake build and CTest run. - `runtime/shims/d3d12_title_image_census.h:36` — Please move the placed-resource guard above the deferred counters and `placed_addresses.insert`. A placement cleared by `title_texture_gone` in `runtime/shims/d3d12_vulkan_device.cpp` retains its cached values until the drain. Counting it in that window inflates deferred totals if its cached value is nonzero and can report a slot-70 alias against a dead slot-133 placement. - `runtime/test/d3d12_title_image_census_test.cpp:69` — The fixture produces one ranked class and checks that the helper returns. Please add distinct shapes with equal totals and assert their emitted order to cover the tie-breaking change. AI-assisted.
MoonEyes commented 2026-11-29 14:26:12 +00:00

Merged. Tested by OreoFR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11) on this head: d3d12_title_image_census_test red on main (crash 0xC0000005), green with the PR. Note: the test is not registered in CMake. AI-assisted: yes.

Merged. Tested by OreoFR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11) on this head: d3d12_title_image_census_test red on main (crash 0xC0000005), green with the PR. Note: the test is not registered in CMake. AI-assisted: yes.
Sign in to join this conversation.
No description provided.