Repository navigation
indirect_draw_stats: guard null FILE* in report and out-of-range Event in note/skip - #2309
Conversation
wavehs
left a comment
There was a problem hiding this comment.
macOS arm64 check of #2309 (indirect_draw_stats guards). Portable header plus its CPU test; runs here without a GPU.
Tested head 25aed3fcb merged onto main bdbc7e923 as merge 9d8a3484d (clean, no conflicts).
Environment: Apple M3 Pro arm64, macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, CPython 3.15.2.
On the merge
- Compiling the new test directly (
clang++ -std=c++20 -I runtime ... runtime/test/indirect_draw_stats_test.cpp) and running it printsindirect_draw_stats_test: ok, exit 0. The valid-skip path formatsrecord_skips=1 [topology=1], andreport(nullptr)is a silent no-op. - The three guards are the right ones:
Counts::reportchecksout,noterejectsEvent >= 4before indexingvalues[], andskiprejects an out-of-rangeEventas well asReason(it then callsnote(event), so without the first check the second would still indexvalues[event]).
Negative control (test kept, runtime/src/indirect_draw_stats.h reverted to main)
- Plain build: run exits 139 (SIGSEGV) at
local.report(nullptr). - To show the other guard is real, I reverted the header and re-applied only the
if (!out) return;line, then rebuilt with-fsanitize=address:AddressSanitizer: global-buffer-overflowatmain+0x528, i.e.note(Event(99))writingvalues[99]past the 4-element array. So theEventcheck is load-bearing, and like thememoryTypeCountcase in #2308 it only diagnoses itself under a sanitizer once the earlier crash is fixed.
Finding: the new test is never built or run - it is not in runtime/CMakeLists.txt
runtime/test/indirect_draw_stats_test.cpp is new, but runtime/CMakeLists.txt has no target or add_test for it (grep finds nothing; ctest -N has no indirect_draw_stats entry). Every test in runtime/test is registered explicitly, so this file is dead in ctest, the Windows runtime job and Wine. tests/test_ctest_registration.py still passes, because it only checks that a target which exists has an add_test; it cannot see a .cpp with no target at all. This is the second PR in this batch with the same shape (#2333 has vulkan_memory_budget_test.cpp unregistered the same way); I filed the guard gap in the coordination issue (#1608) as finding: tests/test_ctest_registration.py cannot see a test file that was never given a CMake target. For this PR the fix is the usual three lines:
add_executable(indirect_draw_stats_test test/indirect_draw_stats_test.cpp)
target_link_libraries(indirect_draw_stats_test PRIVATE Vulkan::Headers) # not even needed; header is standalone
add_test(NAME indirect_draw_stats COMMAND indirect_draw_stats_test)
and it then runs on every platform.
Nits: the 4u in note/skip duplicates the array size (values[4]); a named constant would keep them in step if another event is added. Same for the test's Event(4)/Event(99) literals, which is fine as a regression value.
Not run: the D3D12 path that consumes these counters (Windows-only); the header itself is stage-independent and no GPU is needed.
python -I scripts/check_no_game_data.py on both changed files: clean.
No game files. AI-assisted.
|
Red (
|
|
Verified by OreoFR
AI-assisted (Claude Code, Claude Opus 5.5). |
|
Tested Blocker: add_executable(indirect_draw_stats_test test/indirect_draw_stats_test.cpp)
add_test(NAME indirect_draw_stats COMMAND indirect_draw_stats_test)Hand-compiled (
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
left a comment
There was a problem hiding this comment.
Static audit of 25aed3fcb against the base code. I ran no builds, tests, or GPU workloads.
The guards in runtime/src/indirect_draw_stats.h are correct for the current enum on MSVC and Linux. Event is a scoped enum with a fixed, signed int underlying type, so static_cast<Event>(-1) is defined and converts to UINT_MAX when checked as unsigned. The comparison against 4u matches the four counter slots, and Event has no Count sentinel. skip rejects invalid events before logging or incrementing a reason counter. report(nullptr) returns before formatting or calling fprintf, and the overlay reader in runtime/src/dev_overlay.h indexes the counters with named enumerators.
- Please register
runtime/test/indirect_draw_stats_test.cppin the commonBUILD_TESTINGblock atruntime/CMakeLists.txt:861. The Windows and Linux CTest jobs currently omit it, so the new regression cases receive no coverage in those jobs. - At
runtime/test/indirect_draw_stats_test.cpp:24, usereason_tag(Reason::reason_count)to check the"unknown"fallback.Reasonis an unfixed enum with a value range of 0 through 31, so casting 999 to it is undefined before the fallback can run.
AI-assisted.
|
Merged. Tested by OreoFR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11) on this head: indirect_draw_stats_test red on main (crash 0xC0000409), green with the PR. Note: the test is not registered in CMake. AI-assisted: yes. |
Fixes null-pointer and out-of-bounds bugs in
runtime/src/indirect_draw_stats.h:Counts::report(std::FILE* out)againstout == nullptrbefore callingstd::fprintf(out, ...).static_cast<unsigned>(event) < 4uinnote(Event)andskip(Event, Reason)so an out-of-rangeEventcannot index pastCounts::values[4]or record a stray reason skip.runtime/test/indirect_draw_stats_test.cpp.Verification
g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic -Iruntime/src runtime/test/indirect_draw_stats_test.cpppassedg++ -std=c++20 -fsanitize=address,undefined -Wall -Wextra -Werror -pedantic -Iruntime/src runtime/test/indirect_draw_stats_test.cpppassedubiq/mainpython3 -I scripts/check_no_game_data.py runtime/src/indirect_draw_stats.h runtime/test/indirect_draw_stats_test.cppcleanClaimed in the coordination issue as: RT-INDIRECT-DRAW-STATS-BOUNDS-AND-NULL (#1608 (comment))
AI-assisted: yes (Gemini)