Skip to content

xdxr_bvh: validate negative/kind bounds in ptr() and non-finite transforms in invert_affine() - #8788

Open
cristianvaz wants to merge 1 commit into
ItsNotRexed:mainfrom
cristianvaz:fix/xdxr-bvh-ptr-invert-validation
Open

cristianvaz wants to merge 1 commit into
ItsNotRexed:mainfrom
cristianvaz:fix/xdxr-bvh-ptr-invert-validation

Conversation

@cristianvaz

Copy link
Copy Markdown

Claimed in #8683: #8683 (comment)

Summary

Adds missing bounds and finiteness checks to ptr() and invert_affine() in tools/xdxr_bvh.py:

  • ptr(offset, kind) (tools/xdxr_bvh.py:75-84): Rejects negative offsets (offset < 0) and invalid 3-bit node types (not 0 <= kind <= 7) with ValueError, instead of returning negative integers (which later fail struct.pack_into("<I", ...) with struct.error) or corrupting the pointer's offset bits.
  • invert_affine(m) (tools/xdxr_bvh.py:169-185): Rejects non-finite matrix entries (NaN, +-inf) and non-finite determinants with ValueError, instead of silently producing NaN inverse matrices when det == 0 is False for NaN or inf.

Scope & Conflict Check

Verification

AI-assisted. Tested on Windows 11, Python 3.12.10 (GPU: AMD Radeon RX 9070, driver 32.0.32029.2010; CPU-only tests, synthetic inputs only, zero game data):

Command Result
python -I tests/test_xdxr_bvh_bounds.py 2/2 passed
python -I tests/test_xdxr_bvh.py 47/47 passed
python -I tools/xdxr_bvh.py selftest 4/4 scenes passed (0 validation errors, 0/400 rays differ)
python -m compileall -q make_game.py tools tests exit 0
python -I scripts/check_no_game_data.py tools/xdxr_bvh.py tests/test_xdxr_bvh_bounds.py exit 0

@Grimkeh Grimkeh left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Independent Linux CPU review (ae576c4d)

What changed: xdxr_bvh validates negative/kind bounds in ptr() and non-finite transforms in invert_affine().

Checked: test_xdxr_bvh_bounds 2 OK.

Looks correct; no game files.

@abnalstlll-byte abnalstlll-byte 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.

Verified on Windows 11 (Python 3.14.7).

  • Hardens \ ools/xdxr_bvh.py:
    • \ptr()\ strictly validates \offset >= 0\ and node kind \

@garuspl

garuspl commented Nov 23, 2026

Copy link
Copy Markdown

Tested ae576c4 on Windows 11 (CPU only, no GPU needed): pass

Windows 11 Pro, Python 3.14.7, no GPU or game files involved; pytest/numpy/Pillow pinned from tests/requirements.txt in a fresh venv. Method: PR head merged onto main 867d922, the PR's test files run with python -m pytest before and after the merge, plus python -m compileall -q on the changed files (clean).

  • tests/test_xdxr_bvh_bounds.py (new): 2 passed, 6 subtests passed.

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

@RAINighty

Copy link
Copy Markdown

Tested ae576c4dc merged with main 867d922f0 (clean merge) on Windows 11 (10.0.26300), Python 3.13.15 in UTF-8 mode (PYTHONUTF8=1; venv with the pinned tests/requirements.txt), with llvm-mc 21.1.8 (AMDGPU) and SPIRV-Tools v2026.4 on PATH: pass.

  • tests/test_xdxr_bvh_bounds.py with this PR: passes (Ran 2 tests in 0.000s, OK). On main: a new file, so there is nothing to run there.
  • Negative control: this PR's test with main's version of tools/xdxr_bvh.py fails (Ran 2 tests in 0.005s, FAILED (failures=5)), so the new test does catch the problem.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@Running-Agama

Copy link
Copy Markdown

Independent check on Windows (no game files). Both guards are correct and the tests fail without them.

Run on Windows 11 (10.0.26100), CPython 3.15.0, python -I tests/test_xdxr_bvh_bounds.py:

tree result
PR head ae576c4d 2 tests, OK
same tests with main's tools/xdxr_bvh.py (restored after) 2 tests, FAILED (failures=5)

The test covers negative offsets, misalignment still rejected, kinds -1/8/255, a NaN/±inf entry in the 3x4, and the 1e200³ == inf determinant overflow, plus a finite matrix round-trip.

Minor: an overflowing finite determinant is reported as "singular instance transform". It is non-invertible in float, so rejecting is right; saying "singular or overflowing" would save the next reader a trip. Same for ptr()'s message, which now lumps "negative" and "not aligned" together — fine, just noting it is all a caller sees.

AI-assisted review (OpenCode).

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.

6 participants