Skip to content

skin_streams: validate the dictionary first-child pointer - #2836

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
sds-228:skin-streams-dictionary-child-pointer
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
sds-228:skin-streams-dictionary-child-pointer

Conversation

@sds-228

@sds-228 sds-228 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new BUILD item — #2716 (comment)

What and why

A reviewer on #2610 pointed out that tools/skin_streams.py:resource_kind stops at the dictionary count checks (#2610 (comment)). The pinned rpf9-explorer's DrawableDictionaryCheckBytes also resolves the child-pointer array named by +48: when that array is inside the supplied prefix, its first child must be a system pointer. The Python classifier accepted headers the decoder rejects, counting them as resources before the walker skipped them.

This adds that last check. When the array lies beyond the prefix, the decoder accepts without reading it, so this does too. An invalid first child falls through to the other resource kinds, matching the decoder's LooksLikeResource order. Related: #2610 touches the same branch but a different line; no code dependency.

Tested

  • python -I tests/test_skin_streams.py — 28 tests pass, including 4 new synthetic header tests. I watched the two negative tests fail before the fix.
  • python -m compileall -q make_game.py tools tests and git diff --check — clean.
  • Standard-library sweep: 224 test files, 1 unrelated failure (tests/test_report_paths.py, a macOS case-sensitive-volume assertion that fails on Windows path normalization). Our diff touches neither file.
  • Counts-only check on my own package: 89 dictionary signatures on data.rpf, all with valid in-prefix first children, so 0 reclassified; resources 2,322 before and after, skipped 80 before and after. No bytes, names or offsets quoted.
  • CPU only; no GPU or driver involved.

AI-assisted: OpenCode (Big Pickle model).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • No translator rule or contract-table change; this is a Python resource-header classifier.

AI-assisted (OpenCode).

@toeeshchaudhary toeeshchaudhary 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.

The pointer is checked before dereferencing a complete eight-byte entry, and the header-only classification is retained when the entry lies beyond the prefix. All 28 skin-stream tests passed on Windows.

@padhossein

Copy link
Copy Markdown
Contributor

Independent dictionary prefix boundary sweep (93837c2b). All 28 project tests passed. I tested an additional 28 synthetic combinations near the last fully readable QWORD in a 192-byte prefix: offsets 176/183/184/185/191/192/193, each with null, system, graphics and unrelated first pointers. The base matched 19/28 of the intended classifications and the new code matched 28/28, including the exact last readable byte range beginning at offset 184 and the partial word at 185.

AI-assisted (Codex).

@kacper-serewis kacper-serewis 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.

Independent Windows CPU retail check. Complete skin_streams.py JSON reports matched between ec8ec4c and 93837c2 on the three top-level data.rpf, packs.rpf and levels.rpf archives. Of 46,788 dictionary candidates, 46,464 had a valid in-prefix first child and 324 had the first-child slot beyond the prefix. All retained their classification. An independent prefix walk confirmed every child header in 45,379 dictionaries. The remaining 1,409 were unconfirmed by that stricter check. No invalid in-prefix first child occurred, so rejection remains covered by synthetic tests. Nested archives and other package files were outside the run. #2610 was absent from both revisions. 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 -> 28 OK; the focused dictionary-child class 4/4. On current main the two negative tests fail (2 failures, 2 pass), so the pointer bound is exercised. The condition matches the pinned rpf9-explorer DrawableDictionaryCheckBytes, including the values > len-8 boundary and sys_ptr(first). Synthetic bytes only; no game data or absolute paths. Approve.

Non-blocking: the pinned decoder also requires sys_ptr(+8) and validates the child header at first + 176; Python still returns "dictionary" for a synthetic header with +8 = 0x12345678, so “last check”/full parity is overstated.

@tupacfan04

Copy link
Copy Markdown
Contributor

PASS. Python-only, non-draft, merge clean; tests/test_skin_streams.py 38/38 and compileall clean. Negative control: main's tool with these tests gives exactly the two intended failures (AssertionError: 'dictionary' is not None) for the null/non-system child cases. The logic at tools/skin_streams.py:123-124 matches the existing sys_ptr/s_off conventions, and non-dictionary results fall through as described.

Coverage note, not a defect: the "array beyond prefix" test (tests/test_skin_streams.py:262) uses a 192-byte synthetic buffer while production data is the whole inflated stream, so the boundary between 184 and the stream length is not exercised. One page-sized case with child_at just past 184 would close it.

Approve. AI-assisted review, no game files, no GPU.

@iiroak

iiroak commented Nov 23, 2026

Copy link
Copy Markdown

Independent review of current head d721e851f17b18fb628955dedc1449ad47668448: checked resource_kind against the pinned rpf9-explorer decoder at e2939175c36a02d6ed25fa2c217b9d6ddcb8b516. The new guard validates the first child pointer when its entry is in the supplied prefix and retains the decoder's out-of-prefix behavior; the fixtures cover null, non-system, system, and out-of-prefix pointers. No new blocking finding; the prior non-blocking review note remains unchanged. I did not rerun the PR-specific suite or use game files/hardware.

@MichaelL401

Copy link
Copy Markdown

Tested d721e851 merged onto main d0835dd9 on Linux (Python 3.13, CPU only, no GPU, no game files): pass.

  • python -I tests/test_skin_streams.py: OK, including the four new TestResourceKindDictionaryChild cases.
  • Read the change against DrawableDictionaryCheckBytes in the pinned rpf9-explorer (e293917, Core/RageModelDecoder.cs): same rule. A child-pointer array beyond the prefix is accepted, and inside the prefix the first child must be a system pointer. sys_ptr uses the same 32 MiB bound as SystemPointer.

AI-assisted review.

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.

9 participants