Skip to content

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

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

Persudes wants to merge 1 commit into
ItsNotRexed: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
Contributor

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).

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.

5 participants