Skip to content

skin_streams: bounds-check vertex-buffer pointers and track true weight-sum min/max - #3060

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
leoleahy:fix/skin-streams-gfx-at-weight-min-max
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
leoleahy:fix/skin-streams-gfx-at-weight-min-max

Conversation

@leoleahy

Copy link
Copy Markdown
Contributor

Claim: #2891 (comment)

What changed

  1. tools/skin_streams.py:walk_resource() computed gfx_at = u64(sys, vb + 24) - 0x60000000 without checking that vb + 24 pointed inside the graphics page range (0 <= gfx_at <= MAX_GFX - gfx_len), and validate() sliced gfx[mesh.gfx_at:mesh.gfx_at + mesh.gfx_len] without guarding against negative mesh.gfx_at. A non-graphics pointer (0, a 0x50xxxxxx system pointer, or any value < 0x60000000) produced a negative gfx_at that sliced from the tail of gfx instead of being rejected.
  2. tools/skin_streams.py:validate() seeded low = high = 255 before scanning vertex weight sums. Whenever every vertex in a mesh had a total weight below 255 (e.g. 200), weight-sum-max remained clamped at 255; whenever every vertex summed above 255 (e.g. 265), weight-sum-min remained clamped at 255.
  • Added check(0 <= gfx_at <= MAX_GFX - gfx_len) in walk_resource() and guarded validate() / scan_archive() against negative mesh.gfx_at.
  • Seeded low = high = None in validate() so weight-sum-min and weight-sum-max record the mesh's actual minimum and maximum weight sums.
  • Added TestValidate.test_weight_sum_min_max_without_255_vertex and TestValidate.test_non_graphics_vb_pointer_is_rejected in tests/test_skin_streams.py.

No overlap with #2379, #2610, or #2836 (resource_kind only).

Testing

  • Synthetic CPU-only tests, no game files, no GPU.
  • Verified the new tests fail on main (FAILED (failures=6)) and pass with this change.
  • Windows 11 x64, Python 3.14.8:
    • python -m compileall -q make_game.py tools tests -> exit 0
    • python -I tests/test_skin_streams.py -> 26/26 OK
    • python -I tests/test_text_write_line_endings.py -> 2/2 OK

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.

Verified on the PR head: python -I tests/test_skin_streams.py -> 26/26 pass. On current main the same file gives 20 pass / 6 fail (5 bad-pointer or negative-gfx_at cases and 1 weight-sum min/max case), so both changes are exercised. The raw fixture sums are 200 and 265; main reports (200,255) and (255,265), the PR reports (200,200) and (265,265). A pointer at 0x60000000 + MAX_GFX - gfx_len is accepted by the walk then rejected by validate() as buffer-short; +1 is rejected; a negative gfx_at returns buffer-short without tail slicing. No game data or absolute paths. Approve.

Non-blocking: walk_resource enforces 0 < vertices, so the new low/high=None seed is unreachable from the tool's JSON path; a hand-built zero-vertex mesh would emit nulls.

@kacper-serewis

Copy link
Copy Markdown
Contributor

AI-assisted independent Windows CPU validation of parent 1628210 and head e41dd4f. No GPU.

On 64 evenly spaced 2 MiB windows from one retail archive, both revisions accepted 641 complete resources and returned identical mesh records. All 1,080 weighted meshes had in-bounds graphics pointers. Direct summation of weight bytes across all 1,478,926 vertices in those meshes found sums from 127 to 255; both revisions matched the independent per-mesh extrema. This is bounded sample evidence, not package-wide prevalence.

The head passed 26 focused tests; the parent's original suite passed 24. Running the head suite against the parent produced six assertion failures across the two new tests (four malformed pointers, negative-offset slicing, and all-below-255 weights). The head also passed the all-above-255 fixture. Synthetic cases exercise the fixes while retail inputs establish stability in this sample. All raw artifacts remain private.

@tupacfan04

Copy link
Copy Markdown
Contributor

Tested at the head on Windows 11 / Python 3.13.0: tests/test_skin_streams.py 26/26, line endings 2/2, compileall clean. Negative control: the tool from origin/main gives 6 failures (4 pointer subtests, the negative-gfx_at assert, and test_weight_sum_min_max_without_255_vertex), so the tests discriminate.

The diff is right: seeding low/high = None fixes both clamp directions and cannot leak None (it is only set when weight_rows), and the new guard precedes the slice; the old len(data) < gfx_len became redundant, as you say.

Two things before merge:

  • Rebase across open first_light: a levels.rpf world prop through a game VS whose constant layout is read from its listing (TEST-525) #3048 (tools/skin_streams.py:209-214, same hunk); the resolution is trivial - keep this check and all_meshes or. Note that with all_meshes the check also applies to non-skinned meshes, so one bad VB skips the whole resource.
  • tools/skin_streams.py:208 bounds gfx_at by MAX_GFX (224 MB), but resource_gfx is the join of up to 32 graphics pages (:51, :414). A valid mesh in a resource with more than 224 MB of graphics pages now raises Skip and drops the whole resource from the census. Either bound against len(resource_gfx) or document the assumption.

Approve after the rebase. AI-assisted review, no game files, no GPU.

@ItsNotRexed
ItsNotRexed merged commit faae557 into ItsNotRexed:main Nov 22, 2026
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