Skip to content

Accept FootstepSet DATA longer than its counts - #705

Open
Avick3110 wants to merge 2 commits into
Mutagen-Modding:devfrom
Avick3110:footstepset-surplus-data
Open

Avick3110 wants to merge 2 commits into
Mutagen-Modding:devfrom
Avick3110:footstepset-surplus-data

Conversation

@Avick3110

Copy link
Copy Markdown
Contributor

A FootstepSet whose DATA is longer than 4 bytes per FormID counted in XCNT fails to parse with DATA record had unexpected length that did not match previous counts, through both the direct parse and the overlay. The record that hit this, in Skyrim, has XCNT 0, 0, 0, 0, 0 and DATA 00 00 00 00. xEdit sizes each DATA array from its XCNT count and shows the leftover bytes as unused data, and the game reads by the counts too, so both load it.

The fix, applied alike to Skyrim, Fallout 4 and Starfield:

  • A DATA longer than its counts is accepted. Both readers read each list by its count, then move to the end of DATA, so the surplus bytes are skipped and the next subrecord is read from the right place.
  • A DATA shorter than its counts still throws the same error as before.
  • A DATA whose length runs past the end of its record throws.
  • The public GetListCounts(IMutagenReadStream) keeps its signature. It calls an internal overload that also returns where DATA ends.
  • Writing is unchanged, so a re-save drops the surplus. No generated code changes.

Tests in FootstepSetDataLengthTests, each read through the direct parser and the overlay. Skyrim: zero counts with surplus, a populated list with surplus (including surplus that is not a multiple of 4) followed by EDID, a short DATA that throws, a DATA length past the record end that throws, and a matching record that writes back byte-identical. Fallout 4 and Starfield: a populated list with surplus. The surplus tests fail on dev. Mutagen.Bethesda.UnitTests passes on net9.0 and net10.0. Passthrough tests against real game data were not run; could you run them on Skyrim, Fallout 4 and Starfield?

I found this through houseCARL, a tool built on Mutagen, which could not read a Skyrim FootstepSet carrying surplus DATA bytes (Avick3110/houseCARL#1037).

🤖 Generated with Claude Code

Avick3110 and others added 2 commits October 3, 2026 01:49
GetListCounts threw when DATA was not exactly 4 bytes per FormID counted
in XCNT, so a FootstepSet carrying surplus DATA bytes failed to parse.
xEdit sizes each DATA array from its XCNT count and shows the leftover
bytes as unused data, and the game reads by the counts too, so both load
such a record.

Both readers now read each list by its count and then move to the end of
DATA, so the surplus is skipped and the next subrecord is read from the
right place. Only surplus is accepted: a DATA shorter than its counts
throws as before, and a DATA whose length runs past the end of its
record throws. The public GetListCounts keeps its signature and calls an
internal overload that also returns where DATA ends. Writes are driven
by the lists, so a re-save drops the surplus. Skyrim, Fallout 4 and
Starfield share the same code and get the same change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Builds FSTS records from raw bytes and reads each through the direct
parser and the overlay. Skyrim: zero counts with surplus DATA, with EDID
before and after; a populated list with surplus, including surplus that
is not a multiple of 4, followed by EDID; a short DATA that throws; a
DATA length past the end of the record that throws; and a matching
record that writes back byte-identical. The surplus cases also check
that a write drops the surplus. Fallout 4 and Starfield each get a
populated list with surplus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant