Repository navigation
tests: psin_psch decoder rejection paths - #7297
ThomasRuss wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review:
|
| Class | Covers | Acceptance shown in the same class |
|---|---|---|
PmapTests |
decode_pmap raise sites at tools/psin_psch.py:61-92: short header, container fill at +0x08, PMAP fill at +10, size vs. block_count, root id at 0, past the end and with no blocks, blocks outside 0x10..first_section, first block not at 0x10, end not on a 16-byte boundary |
exact end, 16-byte padded end, root=2, non-zero reserved fields reported (reserved_zero=False) but not refused |
PschTests |
decode_psch at :106-156: tag/length, directory past the end (including count=0xFFFFFFFF), first offset ≠ directory end, offsets not strictly ascending or past the section, entry under 4 bytes, struct/enum size mismatch both ways, unknown kind |
structs plus enums, and an empty table |
PsigStnsTests |
decode_psig at :164 (4/9/zero-entry cases) and decode_stns at :171-187 (short count, table past the end, huge count, size not a multiple of 16, data past the end, missing/extra/non-zero padding, empty table without padding) |
[1, 2], [], one 16-byte record with 4 bytes of tail padding |
SchemaTests |
every errors.append in check_psch_schema at :204-228, including both the key and value map errors reported in one case |
resolved array/enum/map descriptors; a zero-size struct is not used as a divisor |
ContainerTests |
parse_psch_container (not PSIN, truncated, each of the four required sections missing), is_psch_container truth table, STDN/STNS prefix mismatch, and the stdn_match is None path when STDN is absent |
build_synthetic_psch_psin() is valid |
Why it is sound
- The builders
pmap,psch,struct_entryandenum_entryuse the decoders' own struct layouts:>IHHH6sand>4Ifor PMAP,>BBHIIwith>IBBHImembers, and>BBHwith>IIqvalues. Each reject case changes one field of an input the class has just shown to be accepted, so a regex match points at a single check. - Several cases pin edges that are easy to break in a refactor:
"offset + length over 32 bits"(0xFFFFFFFF) fixes thatoffset + length > first_sectionis compared in Python integers and must not wrap the way a C port would."gap of a whole row at the end"(a zero-length last block ending at 48 againstFIRST=64) shows that the 16-byte rounding at:91allows partial-row padding only, not a whole missing row."empty table without padding"shows that a zero-count STNS still has to be padded to 16 bytes (expected_len=16)."PSIG payload 4 "keeps the trailing space so the regex cannot also match40.
test_nonzero_reserved_fields_are_reported_not_refusedrecords the current contract: reserved fields atz0and in each row lowerreserved_zeroand are not refused. That is the right thing to pin before anyone tightens it.- The file runs under
python -Iwith a__main__block and nopytestimport. The CI loop that runsfind tests … -name 'test_*.py'(.github/workflows/ci.ymlaround line 160) picks it up as a standalone test, so it needs no separate CI registration.
Nits (not blocking)
- The PMAP
flagsfield (>IHHH, second field) is always passed as0, anddecode_pmapdoes not check it. One line, for exampledecode_pmap(struct.pack(">IHHH6s", 1, 0xFFFF, 0, 2, PMAP_FILL) + rows, …)["flags"] == 0xFFFF, would document that it is passed through unchecked, the same way the reserved fields are handled. ContainerTestsdrops sections withblob.replace(tag.encode(), b"XXXX"), which replaces every occurrence. The synthetic blob fromtest_psin_psch.build_synthetic_psch_psinhas no tag bytes in any payload today, so this works. If that builder changes, a hash or payload that happens to containPMAPorSTNSwould also be rewritten. Replacing only the section-directory entry, or assertingblob.count(tag) == 1first, would make this robust.test_only_a_complete_container_with_the_sections_is_recognisedasserts that a container without PSCH but with PMAP still counts as a PSCH container. This matches the"PMAP" in tags or "PSCH" in tagscheck at:55, but the test name suggests all the sections are needed. A short comment that PMAP alone is enough would help the next reader.test_psin_psch.pyalready hastest_detects_bad_array_descriptor_and_pmap_size_mismatchand a"padding"STNS case, which this file covers again in more detail. The overlap is harmless and needs no change.
Test results (no game files)
| Check | Result |
|---|---|
git diff --check |
PASS |
python -m compileall -q make_game.py tools tests |
PASS |
python -I scripts/check_no_game_data.py on the changed file |
PASS |
python -I make_game.py --help |
PASS |
python -I tests/test_psin_psch_rejects.py (run during this review) |
16 tests, OK in 0.002 s |
The harness found no existing targeted test file for the change, so the only targeted run is the new file itself.
Adherence
- No game data: every input is built in the test from
struct.packand literal bytes such asb"pppppppp", plus the existing hand-madebuild_synthetic_psch_psin(). No archive, carved file or log content is involved, andcheck_no_game_data.pypasses. - No keys or protection workarounds: the change only exercises unencrypted container parsing.
- Nothing online: no network access.
- Fix, don't disable: the change is tests only. It adds no skip list and relaxes no check. It holds the existing validation in place, including keeping the reserved-field checks as reports rather than refusals.
- Conventions: standard library only, runnable with
python -I, and it writes no files, so the line-ending rule does not apply.
The PR adds no new format claims. It tests the checks already in tools/psin_psch.py, so no docs/design.md quote is needed.
Verdict: approve. The nits are optional follow-ups.
AI-assisted.
…dding edges, review points Type codes come from docs/psin.md instead of the tool's constants. Adds multi-block STNS, full enum values, padding edges, the PMAP flags pass-through and the member type histogram, guards the section renaming, and corrects the header and one test name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@tikD1337 Thanks for the review. Points 1 to 3 are addressed in 54a5e27:
Point 4 is left as is, as you suggested. The same commit changes a few things you have not seen: type codes come from AI-assisted (Claude Code). |
sds-228
left a comment
There was a problem hiding this comment.
Re-reviewed at the current head. This adds one synthetic test file only: each decoder and container rejection is pinned to its own message, with acceptance cases beside it in the same classes, so a guard removed or weakened will fail a named case.
CPU-only verification here: 16/16 new tests pass; the 3 existing decoder tests still pass; changing one header-length guard makes exactly one new case fail; the no-game-data check is clean. No GPU or game files involved. Earlier optional nits are non-blocking.
AI-assisted (OpenCode).
|
Tested f65a23c, clean vs main 976b3ec: test_psin_psch_rejects Ran 16 OK both merged AND on clean main — correct for a pure characterization PR documenting current rejection behavior. A mutation probe (deleting the STNS nonzero-padding condition) does turn test_stns red, so the assertions are live, not decorative; tree restored md5-clean with pycache purged. No case overlap with #7301 — complementary. Flag: NO CI checks on the branch. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
|
Tested 54a5e27 on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass. Ran the test files this PR adds or changes, from a clean checkout of the PR head: AI-assisted (Claude Code). |
Claimed in the coordination issue as: #7231 (comment)
What and why
Adds
tests/test_psin_psch_rejects.py: tests only, no change to the tool and no bug fixed.tests/test_psin_psch.pycovers valid containers and a few bad ones, so most error branches ofdecode_pmap,decode_psch,decode_psig,decode_stns,check_psch_schemaandparse_psch_containernever ran; a check removed by accident would not have failed a test. Each bad input must be refused with its own error, and the valid ones must still be accepted. Type codes are the onesdocs/psin.mdgives, not read from the tool. Most cases damage an input the same test class shows to be accepted; the rest are the smallest section that reaches the check.Related pull requests (none is a dependency):
build_synthetic_psch_psinfromtests/test_psin_psch.py, which psin_psch: report missing inputs/unwritable json as ERROR + exit 2 and guard carve-dir streams #6260 and psin_psch: reject overlapping PMAP blocks and duplicate sections #7301 also edit. Neither changes that helper.The new file passes with the
psin_pschchanges of each of the four applied, and with #6260 and #7301 applied together.Tested
Windows 11, CPU only (no GPU or game files):
python -I tests/test_psin_psch_rejects.py: 16 tests pass on Python 3.12 and 3.10 (also under pytest on 3.12)tests/test_psin_psch.py,tests/test_ci_registration.py,tests/test_resource_hygiene.pyandscripts/check_no_game_data.pyon the new file passtests/test_psin_psch.py, and 2 change a constant only the archive scan usesThe second commit follows the review by tikD1337: the PMAP
flagspass-through is pinned (1), renaming a section checks that its tag occurs once (2), and the recognition test is renamed and notes that either tag is enough (3). The overlap with existing tests (4) is left as is.Not run: Linux, macOS, real game files.
AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. (n/a: tests only)Generated with Claude Code