Skip to content

fix(runtime): bound xdxr find_stream_record to complete records and reject unknown types - #5475

Closed
Persudes wants to merge 1 commit into
ProjectLeonida:mainfrom
Persudes:fix/xdxr-stream-record-bounds
Closed

Persudes wants to merge 1 commit into
ProjectLeonida:mainfrom
Persudes:fix/xdxr-stream-record-bounds

Conversation

@Persudes

Copy link
Copy Markdown
Contributor

Summary

Fixes three bounds and validation defects in leonida::xdxr::find_stream_record() (runtime/src/xdxr_descs.h):

  1. Partial-record buffer over-read:
    Previously computed end = (const uint8_t*)desc.stream + desc.size_in_bytes and walked record < end. Any non-multiple of sizeof(StreamRecord) (e.g. 1..15 or 17..31 bytes) inspected and returned a StreamRecord* whose 16 bytes extended past desc.size_in_bytes.
  2. Pointer wraparound UB on large size_in_bytes:
    Adding a huge size_in_bytes (such as ~uint64_t{0}) to desc.stream wrapped around the 64-bit address space so end < record, causing UB and returning nullptr even when records[0] matched.
  3. Unknown requested record types (type > 2) returned as matches:
    Checking record->type == type before record->type > 2 returned an unknown record when querying type > 2 instead of stopping at unknown types (per docs/xdxr.md §3).

Fix (efe94cc7)

  • Guard if (type > 2 || desc.stream == nullptr) return nullptr;.
  • Walk only const uint64_t count = desc.size_in_bytes / sizeof(StreamRecord); complete 16-byte records by index without computing an out-of-bounds end pointer, checking if (records[i].type > 2) return nullptr; first.
  • Changes touch only lines 99-114 of runtime/src/xdxr_descs.h, staying disjoint from open PR XDXR: serialize acceleration structures and record batched builds (RT-148) #4494.

Verification (Windows 11 x64, MSVC 19.52 VS2026 Build Tools, Windows SDK d3d12.h)

  • Red -> Green (runtime/test/xdxr_descs_test.cpp):
    • Before fix: line 77: find_stream_record(StreamDesc{rem, records}, 0) == nullptr (exit 1).
    • After fix (efe94cc7):
      • cmake --build runtime/build --target xdxr_descs_test — 0 errors, 0 warnings.
      • runtime\build\xdxr_descs_test.exe -> xdxr_descs: ok (checked against d3d12.h) (exit 0).
      • ctest --test-dir runtime/build --output-on-failure -R "^xdxr_descs$" -> 1/1 Test #6: xdxr_descs ... Passed.
  • Repo gates: python -I -B tests/test_ctest_registration.py (4/4 OK), scripts/check_no_game_data.py (exit 0), git diff --check (exit 0), CRLF=0, git merge-tree --write-tree upstream/main HEAD (bc292b0093888b746e0ee7a891fba7c849efc422, exit 0).

AI-assisted (Gemini, Antigravity); no copyrighted game files or dumps used.

@LocranKing

Copy link
Copy Markdown
Contributor

Tested efe94cc78 on Windows 11 Home Build 26200 (RTX 3060 Ti, driver 621.01, MSVC 14.44.35207, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~): pass

  • git diff --check HEAD~1..HEAD: clean
  • scripts\build_runtime.ps1: built gta6rt.exe (0 errors; 0 warnings in PR files)
  • runtime\build\xdxr_descs_test.exe: xdxr_descs: ok (checked against d3d12.h) (exit 0)
  • ctest --test-dir runtime/build -R xdxr --output-on-failure -V: 5/5 PASS (xdxr_descs, xdxr_build, xdxr_build_check, d3d12_xdxr_rt, d3d12_xdxr_rt_check; 0 validation errors)

AI-assisted. No game files.

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Tested efe94cc on NVIDIA GeForce RTX 5080 Laptop GPU, driver 621.14, Windows 11 (build 26300), MSVC 14.44, RelWithDebInfo: pass. ctest -R ^xdxr_descs$ passes. Code read: the count-based loop removes the pointer-wrap and partial-record reads, and find_stream_record has no callers outside the test, so refusing type > 2 changes no runtime path. AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head efe94cc7842e · Verdict: LGTM

Built xdxr_descs_test; xdxr_descs_test.exe → exit 0 (xdxr_descs: ok). git diff --check clean.

The walk now uses size_in_bytes / sizeof(StreamRecord), so a partial leading/trailing record is never read; type > 2 is rejected before the walk; a huge size cannot wrap pointer arithmetic. Cases cover all of those. No blockers.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested efe94cc7 merged onto main 3faac557 (merges cleanly) on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: pass.

  • xdxr_descs passes.
  • ctest: 169 passed, 9 skipped, 0 failed; run_gpu_tests.py: 170/217 passed, 47 skipped, 0 failed, same as main 3faac557.

AI-assisted (Claude Code).

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested efe94cc7 on Linux, GCC, CPU only (no GPU, no Windows API), merged onto main 867d922f: pass

  • Built only the xdxr_descs test target(s) from the merged tree and ran them through CTest: 100% tests passed out of 1.
  • With the PR's runtime/src files reverted to main and rebuilt: 0% tests passed, 1 tests failed out of 1.
    • line 77: find_stream_record(StreamDesc{rem, records}, 0) == nullptr

So the new test depends on the change.

From the agent's read, which I did not repeat: the huge-size case in the new test stops on an unknown record type rather than on the new count bound; the partial-record case is the one that fails on main. The agent also built the test under ASan/UBSan and reports it clean; I did not repeat the sanitizer build.

Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting.

Raxstreams added a commit to Raxstreams/Leonida that referenced this pull request Nov 23, 2026
…ProjectLeonida#5182 ProjectLeonida#5215 ProjectLeonida#5281 ProjectLeonida#5310 ProjectLeonida#5351 ProjectLeonida#5447 ProjectLeonida#5068 ProjectLeonida#5166 ProjectLeonida#5277 ProjectLeonida#5282 ProjectLeonida#5475 ProjectLeonida#5158 ProjectLeonida#5183 ProjectLeonida#5200 ProjectLeonida#5384 ProjectLeonida#5427 ProjectLeonida#5466 ProjectLeonida#5471 ProjectLeonida#5365 ProjectLeonida#5382 ProjectLeonida#5405

ProjectLeonida#8919 fork integration. Each parent after the first is an exact reviewed PR head.

ProjectLeonida#5153 88cf9ac ProjectLeonida#5153 (comment)
ProjectLeonida#5157 7d40e36 ProjectLeonida#5157 (comment)
ProjectLeonida#5182 4996abf ProjectLeonida#5182 (review)
ProjectLeonida#5215 d3813da ProjectLeonida#5215 (comment)
ProjectLeonida#5281 c7479ca ProjectLeonida#5281 (comment)
ProjectLeonida#5310 4a92a11 ProjectLeonida#5310 (comment)
ProjectLeonida#5351 d323535 ProjectLeonida#5351 (comment)
ProjectLeonida#5447 3ea2012 ProjectLeonida#5447 (comment)
ProjectLeonida#5068 c677645 ProjectLeonida#5068 (comment)
ProjectLeonida#5166 f38610b ProjectLeonida#5166 (comment)
ProjectLeonida#5277 1890d03 ProjectLeonida#5277 (comment)
ProjectLeonida#5282 e720a87 ProjectLeonida#5282 (comment)
ProjectLeonida#5475 efe94cc ProjectLeonida#5475 (comment)
ProjectLeonida#5158 cd6149d ProjectLeonida#5158 (comment)
ProjectLeonida#5183 411af87 ProjectLeonida#5183 (comment)
ProjectLeonida#5200 8b3e1f6 ProjectLeonida#5200 (comment)
ProjectLeonida#5384 4d86d07 ProjectLeonida#5384 (comment)
ProjectLeonida#5427 18a1ef2 ProjectLeonida#5427 (comment)
ProjectLeonida#5466 59a92c8 ProjectLeonida#5466 (comment)
ProjectLeonida#5471 c85e97a ProjectLeonida#5471 (comment)
ProjectLeonida#5365 24da2a0 ProjectLeonida#5365 (comment)
ProjectLeonida#5382 4ce3ce2 ProjectLeonida#5382 (comment)
ProjectLeonida#5405 f29b3eb ProjectLeonida#5405 (comment)

AI-assisted integration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants