indirect_draw_stats: guard null FILE* in report and out-of-range Event in note/skip #2309
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2309"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-26T13:40:49Z.
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 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193658432)
AI-assisted: yes (Gemini)
Imported from ubiquitarianism/leonida. Originally posted by wavehs on 2026-11-26T19:43:03Z.
Review: COMMENTED
macOS arm64 check of #2309 (indirect_draw_stats guards). Portable header plus its CPU test; runs here without a GPU.
Tested head
25aed3fcbmerged ontomainbdbc7e923as merge9d8a3484d(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
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.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.hreverted tomain)local.report(nullptr).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.txtruntime/test/indirect_draw_stats_test.cppis new, butruntime/CMakeLists.txthas no target oradd_testfor it (grepfinds nothing;ctest -Nhas noindirect_draw_statsentry). Every test inruntime/testis registered explicitly, so this file is dead in ctest, the Windows runtime job and Wine.tests/test_ctest_registration.pystill passes, because it only checks that a target which exists has anadd_test; it cannot see a.cppwith no target at all. This is the second PR in this batch with the same shape (#2333 hasvulkan_memory_budget_test.cppunregistered the same way); I filed the guard gap in the coordination issue (#1608) asfinding: 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:and it then runs on every platform.
Nits: the
4uinnote/skipduplicates the array size (values[4]); a named constant would keep them in step if another event is added. Same for the test'sEvent(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.pyon both changed files: clean.No game files. AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:16:05Z.
VERIFY-2309— verified head25aed3fcb1merged cleanly withmaind48a957bbon Windows 11 Pro (build 26200), MSVC19.44(x64,/std:c++20 /W4 /WX /permissive- /utf-8 /EHsc), synthetic indirect-draw counters only.Red (
maind48a957bb) -> Green (d48a957bb+25aed3fcb1)main:runtime/test/indirect_draw_stats_test.cppagainstmain'sruntime/src/indirect_draw_stats.h-> FAILED with0xC0000409(STATUS_STACK_BUFFER_OVERRUN/ UCRT invalid-parameter fastfail) whenlocal.report(nullptr)passed a nullFILE*tostd::fprintf.cl.exe /nologo /std:c++20 /W4 /WX /permissive- /utf-8 /EHsc /I"runtime/src" runtime/test/indirect_draw_stats_test.cpp-> 0 warnings, exit0(indirect_draw_stats_test: ok), confirming bothreport(nullptr)no-op behavior and out-of-rangeEvent(>= 4) bounds guards innote()/skip().runtime/test/indirect_draw_stats_test.cppusesstd::tmpfile(), which on Windows UCRT opens a file in the root of the current working drive (passes on writable non-system drives, though non-elevated runs rooted on a protected system drive root can getnullptr).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:01:46Z.
Verified by OreoFR
c1ecf04ed+ PR head25aed3fcb; green run in a merge package of 16 PRs, no new ctest failure vs mainstandalone build of indirect_draw_stats_test.exe (the test is not registered in CMake)AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T22:49:45Z.
Tested
25aed3fcbmerged (no commit) withmainaa918e5d9, MSVC 19.52 (Visual Studio 18), Windows 11 10.0.26300.Blocker:
runtime/test/indirect_draw_stats_test.cppis new but is not registered inruntime/CMakeLists.txt, so neither CI norctestever builds or runs it.ctest -Non the merge lists no such test, andtests/test_ctest_registration.pystill passes, so nothing catches this. Registering it the way the other header-only tests are would fix that:Hand-compiled (
cl /std:c++20 /EHsc /O2):indirect_draw_stats_test: ok, exit 0.runtime/src/indirect_draw_stats.hback tomain: crash, exit0xC0000409.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).
Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T04:27:27Z.
Review: COMMENTED
Static audit of
25aed3fcbagainst the base code. I ran no builds, tests, or GPU workloads.The guards in
runtime/src/indirect_draw_stats.hare correct for the current enum on MSVC and Linux.Eventis a scoped enum with a fixed, signedintunderlying type, sostatic_cast<Event>(-1)is defined and converts toUINT_MAXwhen checked asunsigned. The comparison against4umatches the four counter slots, andEventhas noCountsentinel.skiprejects invalid events before logging or incrementing a reason counter.report(nullptr)returns before formatting or callingfprintf, and the overlay reader inruntime/src/dev_overlay.hindexes the counters with named enumerators.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.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.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T14:26:34Z.
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.