WIP: fix(fs): name game files bigger than their size-table entry, and listed files not found #2173

Draft
HumanBean wants to merge 2 commits from HumanBean/Longshot:fix/fs-size-table-check into main
Owner

Summary

The game closes when an actor fails to be created. That happens when a file the actor needs doesn't load: the file is
missing, damaged, or bigger than its entry in the game's resource size table, which sets the size of the buffer the game
loads it into. Neither the game nor the builder said which file it was, so players and we were left guessing from a
crash (#1499, #1761).

This change names those files:

  • In the game (host/fs_sizes.c, called from OpenFile in host/nn_fs.c). When the game opens its size table,
    the table it was served is read once: the RomFS's own, the button prompts' with the font's entry raised (#2092), or
    the mods' merged one. After that, listed content: files are checked against their entries, except .mc files. A .zs file's size is the
    one its zstd frame states, from its header as the game reads it; files whose headers are never read in full may not be
    checked. Any other file's size is its own. Up to 64 distinct files bigger than their entries are logged once, as warnings:
    fs: <path> is N bytes, its size-table entry M: the game drops it (a damaged or mismatched dump?).
    The first 20 distinct listed .zs files that aren't found are logged too:
    fs: <path> not found, and the size table lists it: the game drops it (an incomplete dump?).
    Only a real not-found open counts (ERROR_FILE_NOT_FOUND / ERROR_PATH_NOT_FOUND, ENOENT / ENOTDIR on Linux): a file
    in use or refused isn't called missing. Past the 20th, one line says more are missing. This doesn't need HOS_FS_TRACE.
  • In the builder (nup.size_table_check, make_game.check_size_tables). Once the RomFS is unpacked or chosen, its files are checked against each readable ResourceSizeTable.* in it. Unreadable tables are reported. The build log names up to 50 file comparisons that exceed an entry, then gives a count; these comparisons are inconclusive unless the game uses that table. When the RomFS has more than one table (a base dump with an update over
    it), the build warns that the game reads only its own version's. This is a warning, not a stop: a mod can raise an
    entry.

Missing files are limited to listed .zs files because normal play asks for many files that aren't there. An earlier
HOS_FS_TRACE run on this PC (a good dump, Castle Town) logged 744 content: opens as not found: textures and settings
the game looks for in turn. 345 distinct paths aren't in the size table at all. The 4 that are listed aren't .zs
files (uncompressed settings the game goes on without). A check of this PC's good dump
found 0 of its 186,583 files bigger than their entries.

Read first: host/fs_sizes.c, the hook in host/nn_fs.c OpenFile, then nx2/nup.py size_table_check and
nx2/make_game.py check_size_tables.

See #1499, #1761

Testing

Tested: Linux, RTX 3090, NVIDIA 620.70.06, this PR @ 635af081 as a pack (106 s, the lifted C unchanged) over main's base, through the job queue:

  • A memory tour from kokiri-start through the Market, Hyrule Castle, Hyrule Field and Kokiri Forest: in play, clean quit, and no fs: line with size-table entry, the size table lists it or cannot be read as a resource size table.
  • The same game with an oversized copy of one listed texture (Tex/Gradation_Ramp_05_Fi.bntx.zs, its frame stating 4096 bytes past its entry) through HOS_FS_OVERLAY, Market then Hyrule Castle: the log has fs: Tex/Gradation_Ramp_05_Fi.bntx.zs is 33160 bytes, its size-table entry 29064: the game drops it (a damaged or mismatched dump?) exactly once. The oversized file stayed on this PC and was deleted after.

Game-free checks: tests/test_fs_size_check.py builds the actual host/fs_sizes.c, host/zs.c and host/restbl.c with
zstd's decoder over a made-up RomFS. It covers the served table being read rather than the RomFS's own, the table read
once when opened twice, and a bigger .zs file named once with its stated size. A file that fits, one that isn't
listed, a .mc file, one opened before the table and one on another mount aren't named. A file that isn't .zs is
held to a named entry by its own size. Of the listed .zs files not found, the first 20 are named. Listed files that
aren't .zs and unlisted files aren't. A table that can't be read is reported. tests/test_builder_size_table.py
covers nup.size_table_check: bigger files named, and damaged, size-less, .mc and unlisted files skipped. It also
covers a table made with a ZsDic dictionary, two tables (the warning, each file against each), and
check_size_tables: named in the log, checked again when files or tables change, unreadable tables reported, and nothing written without a table. The two existing harnesses that compile OpenFile
(tests/test_vcore_fs_open.py, tests/test_damaged_rom_files.py) got stubs for the two new calls. No test was run
on this PC (its rule: CI on the forge runs them). Both new tests fail on main, where neither function exists.

Still to test:

  • Windows (any GPU): a start and a minute of play, expecting no new fs: warnings. This checks the table read with an
    OVERLAPPED offset on the game's handle (@Beanstalk start the game and play a minute in Kokiri Forest; the log must
    have no line containing "size-table entry" or "the size table lists it")

Measurements

The game-side check adds no file reads: hos_fs_sizes_read keeps the bytes of a .zs file's first 18 that the game
itself reads, in whatever parts and order, and checks the stated size once they're held from byte 0. The game reads the table once, when it opens it (about 220,000 entries, about 1.7 MB kept). After
that, checks use a CRC-32 lookup (a binary search, plus 10 named entries). For .zs files, the check uses header bytes
from the game's reads. The builder does one 18-byte header read for each listed .zs file (about 186,000) on each build, with no
marker. Still to measure: a clean build's time against main's, cold and warm, and loading in play, before this
leaves WIP. The Linux runs in Tested were on the earlier head (an extra read per open); they're redone with those.

Risks

  • A listed .zs file that normal play asks for and that isn't there on a good dump would log up to 20 false lines. The
    Castle Town trace had none; the memtour above checks Kokiri Forest and the areas it visits.
  • The table is read from the game's own handle at offset 0 before OpenFile returns; the read is positional, so the game's reads aren't affected. Compressed file checks use the game's reads.
  • Revert to undo. Players see new warnings for these problems or an unreadable size table. An old .longshot_sizes_checked note is removed on the next check.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named). (no tests run on this PC; CI runs them)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here. (fails on main: neither function exists; passing
    here is up to CI)
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (syntax-checked with gcc on Linux only; the
    build is to run)
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary The game closes when an actor fails to be created. That happens when a file the actor needs doesn't load: the file is missing, damaged, or bigger than its entry in the game's resource size table, which sets the size of the buffer the game loads it into. Neither the game nor the builder said which file it was, so players and we were left guessing from a crash (#1499, #1761). This change names those files: - **In the game** (`host/fs_sizes.c`, called from `OpenFile` in `host/nn_fs.c`). When the game opens its size table, the table it was served is read once: the RomFS's own, the button prompts' with the font's entry raised (#2092), or the mods' merged one. After that, listed `content:` files are checked against their entries, except `.mc` files. A `.zs` file's size is the one its zstd frame states, from its header as the game reads it; files whose headers are never read in full may not be checked. Any other file's size is its own. Up to 64 distinct files bigger than their entries are logged once, as warnings: `fs: <path> is N bytes, its size-table entry M: the game drops it (a damaged or mismatched dump?)`. The first 20 distinct listed `.zs` files that aren't found are logged too: `fs: <path> not found, and the size table lists it: the game drops it (an incomplete dump?)`. Only a real not-found open counts (ERROR_FILE_NOT_FOUND / ERROR_PATH_NOT_FOUND, ENOENT / ENOTDIR on Linux): a file in use or refused isn't called missing. Past the 20th, one line says more are missing. This doesn't need `HOS_FS_TRACE`. - **In the builder** (`nup.size_table_check`, `make_game.check_size_tables`). Once the RomFS is unpacked or chosen, its files are checked against each readable `ResourceSizeTable.*` in it. Unreadable tables are reported. The build log names up to 50 file comparisons that exceed an entry, then gives a count; these comparisons are inconclusive unless the game uses that table. When the RomFS has more than one table (a base dump with an update over it), the build warns that the game reads only its own version's. This is a warning, not a stop: a mod can raise an entry. Missing files are limited to listed `.zs` files because normal play asks for many files that aren't there. An earlier `HOS_FS_TRACE` run on this PC (a good dump, Castle Town) logged 744 `content:` opens as not found: textures and settings the game looks for in turn. 345 distinct paths aren't in the size table at all. The 4 that are listed aren't `.zs` files (uncompressed settings the game goes on without). A check of this PC's good dump found 0 of its 186,583 files bigger than their entries. Read first: `host/fs_sizes.c`, the hook in `host/nn_fs.c` `OpenFile`, then `nx2/nup.py` `size_table_check` and `nx2/make_game.py` `check_size_tables`. See #1499, #1761 ## Testing **Tested:** Linux, RTX 3090, NVIDIA 620.70.06, this PR @ 635af081 as a pack (106 s, the lifted C unchanged) over main's base, through the job queue: - A memory tour from `kokiri-start` through the Market, Hyrule Castle, Hyrule Field and Kokiri Forest: in play, clean quit, and no `fs:` line with `size-table entry`, `the size table lists it` or `cannot be read as a resource size table`. - The same game with an oversized copy of one listed texture (`Tex/Gradation_Ramp_05_Fi.bntx.zs`, its frame stating 4096 bytes past its entry) through `HOS_FS_OVERLAY`, Market then Hyrule Castle: the log has `fs: Tex/Gradation_Ramp_05_Fi.bntx.zs is 33160 bytes, its size-table entry 29064: the game drops it (a damaged or mismatched dump?)` exactly once. The oversized file stayed on this PC and was deleted after. Game-free checks: `tests/test_fs_size_check.py` builds the actual `host/fs_sizes.c`, `host/zs.c` and `host/restbl.c` with zstd's decoder over a made-up RomFS. It covers the served table being read rather than the RomFS's own, the table read once when opened twice, and a bigger `.zs` file named once with its stated size. A file that fits, one that isn't listed, a `.mc` file, one opened before the table and one on another mount aren't named. A file that isn't `.zs` is held to a named entry by its own size. Of the listed `.zs` files not found, the first 20 are named. Listed files that aren't `.zs` and unlisted files aren't. A table that can't be read is reported. `tests/test_builder_size_table.py` covers `nup.size_table_check`: bigger files named, and damaged, size-less, `.mc` and unlisted files skipped. It also covers a table made with a ZsDic dictionary, two tables (the warning, each file against each), and `check_size_tables`: named in the log, checked again when files or tables change, unreadable tables reported, and nothing written without a table. The two existing harnesses that compile `OpenFile` (`tests/test_vcore_fs_open.py`, `tests/test_damaged_rom_files.py`) got stubs for the two new calls. No test was run on this PC (its rule: CI on the forge runs them). Both new tests fail on `main`, where neither function exists. **Still to test:** - Windows (any GPU): a start and a minute of play, expecting no new `fs:` warnings. This checks the table read with an `OVERLAPPED` offset on the game's handle (@Beanstalk start the game and play a minute in Kokiri Forest; the log must have no line containing "size-table entry" or "the size table lists it") ## Measurements The game-side check adds no file reads: `hos_fs_sizes_read` keeps the bytes of a `.zs` file's first 18 that the game itself reads, in whatever parts and order, and checks the stated size once they're held from byte 0. The game reads the table once, when it opens it (about 220,000 entries, about 1.7 MB kept). After that, checks use a CRC-32 lookup (a binary search, plus 10 named entries). For `.zs` files, the check uses header bytes from the game's reads. The builder does one 18-byte header read for each listed `.zs` file (about 186,000) on each build, with no marker. **Still to measure:** a clean build's time against main's, cold and warm, and loading in play, before this leaves WIP. The Linux runs in Tested were on the earlier head (an extra read per open); they're redone with those. ## Risks - A listed `.zs` file that normal play asks for and that isn't there on a good dump would log up to 20 false lines. The Castle Town trace had none; the memtour above checks Kokiri Forest and the areas it visits. - The table is read from the game's own handle at offset 0 before `OpenFile` returns; the read is positional, so the game's reads aren't affected. Compressed file checks use the game's reads. - Revert to undo. Players see new warnings for these problems or an unreadable size table. An old `.longshot_sizes_checked` note is removed on the next check. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). (no tests run on this PC; CI runs them) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A fix: a game-free test that fails on `main` and passes here. (fails on `main`: neither function exists; passing here is up to CI) - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (syntax-checked with gcc on Linux only; the build is to run) - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Game-free checks for #1499 and #1761: host/fs_sizes.c over a made-up RomFS (the served table, a .zs file's
stated size, the first 20 listed files not found) and nx2/nup.py size_table_check with make_game's
check_size_tables (each file bigger than its entry, two tables, checked once per RomFS). They fail on main:
neither exists there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(fs): name game files bigger than their size-table entry, and listed files not found
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 23s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 29s
CI / Workflow lint (actionlint) (pull_request) Successful in 36s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 37s
CI / Website build and checks (pull_request) Failing after 41s
Third-party parts / As their notes say (pull_request) Successful in 43s
635af08102
The game drops a file bigger than its entry in the resource size table, or missing, and aborts when an
actor needs it (#1499, #1761); nothing said which file. host/fs_sizes.c, from OpenFile: the table the
game was served is read once when the game opens it; each content: file opened after it is held to its
entry (a .zs file's frame-stated size from its first 18 bytes, another file's own size) and named once
when bigger; the first 20 listed .zs files not found are named (normal play asks for many unlisted files
that are not there). The builder holds every RomFS file to the tables once per RomFS (one 18-byte header
read per listed .zs file), names each bigger one, and warns when the RomFS has more than one table.

See #1499, #1761

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

Tested in game: Linux, RTX 3090, NVIDIA 620.70.06, through the job queue: memory tour Market/Hyrule Castle/Field/Kokiri, in play, clean quit, no new fs: lines; with one oversized listed texture through HOS_FS_OVERLAY the 'is N bytes, its size-table entry M' line appeared exactly once. Pack 106 s. Windows ReadFile path needs the Test Farm.

Tested in game: Linux, RTX 3090, NVIDIA 620.70.06, through the job queue: memory tour Market/Hyrule Castle/Field/Kokiri, in play, clean quit, no new fs: lines; with one oversized listed texture through HOS_FS_OVERLAY the 'is N bytes, its size-table entry M' line appeared exactly once. Pack 106 s. Windows ReadFile path needs the Test Farm.
Member

Possibly related, for context:

  • PR #942 WIP: fix(mods): raise the size table entries of the files inside the packs mods serve — Overlapping resource size-table handling in open PR.
Possibly related, for context: - PR #942 WIP: fix(mods): raise the size table entries of the files inside the packs mods serve — Overlapping resource size-table handling in open PR.
Author
Owner
@rebase
Member

I rebased this pull request onto main (8dce60edcd): the new head is df0971b3d2.

Conflicts resolved

  • tests/test_damaged_rom_files.py: Added save types, helpers, locking stubs, and the out-of-memory result needed by the extracted OpenFile.
  • tests/test_fs_save_commit.py: Added size-check stubs for the standalone fixture.
  • Also changed, beyond the conflict: tests/test_damaged_rom_files.py, tests/test_fs_save_commit.py

Nothing was built or run: read the resolution before merging.


Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

I rebased this pull request onto `main` (8dce60edcd6d): the new head is df0971b3d286. **Conflicts resolved** - tests/test_damaged_rom_files.py: Added save types, helpers, locking stubs, and the out-of-memory result needed by the extracted OpenFile. - tests/test_fs_save_commit.py: Added size-check stubs for the standalone fixture. - Also changed, beyond the conflict: `tests/test_damaged_rom_files.py`, `tests/test_fs_save_commit.py` Nothing was built or run: read the resolution before merging. --- <sub>Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
BeanBot force-pushed fix/fs-size-table-check from 635af08102
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 23s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 29s
CI / Workflow lint (actionlint) (pull_request) Successful in 36s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 37s
CI / Website build and checks (pull_request) Failing after 41s
Third-party parts / As their notes say (pull_request) Successful in 43s
to df0971b3d2
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 6s
PR description / Description follows the template (pull_request_target) Successful in 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 21s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 22s
CI / Website build and checks (pull_request) Failing after 24s
Third-party parts / As their notes say (pull_request) Successful in 27s
2026-11-22 01:24:11 +00:00
Compare
BeanBot left a comment

Recommendation: Request changes. The new diagnostics can fail on supported Windows paths, miss changed or unreadable files, and stop a build on a damaged dictionary archive. They can also report files against a table the game does not use.

The change names oversized and missing resources in the game and scans the RomFS during builds. The Linux game run demonstrates one oversized-file warning, but the added scan and runtime checks have correctness and measurement gaps.

@fix will do (11)

  1. L1 host/fs_sizes.c:59: The table is reopened through hos_zs_read's narrow fopen, although OpenFile successfully opened it with UTF-8 to wide conversion and extended-length paths. (more on the line)
  2. L2 host/fs_sizes.c:59: This new runtime caller can enter hos_zs_decode concurrently with the mod or prompt readers. (more on the line)
  3. L3 nx2/nup.py:797: The dictionary archive parser unpacks SFAT nodes without checking that the node array is present. (more on the line)
  4. L4 nx2/make_game.py:793: The clean-check marker tracks the folder and tables but not the files checked. (more on the line)
  5. L5 nx2/nup.py:845: Unreadable or invalid tables are silently discarded, after which an empty result is treated as a clean scan and cached. (more on the line)
  6. L6 nx2/make_game.py:801: The scan compares each file with every table but this message says the game drops every reported file. (more on the line)
  7. L7 (minor) host/fs_sizes.c:119: The limit counts failed opens rather than distinct missing paths. (more on the line)
  8. L8 (minor) host/fs_sizes.c:95: restbl_key silently truncates paths to this 512-byte buffer, while guest paths can be longer. (more on the line)
  9. L9 tests/test_fs_size_check.py:29: The suite forces gcc and skips Windows, so a Linux setup with only Clang or an explicit CC fails or tests the wrong compiler, and the Windows implementation has no game-free coverage. (more on the line)
  10. L10 (its part an edit can do) host/nn_fs.c:1174: Avoid or batch the extra per-open read, or move table initialization off the first-use path.
  11. L11 (its part an edit can do) nx2/make_game.py:799: Combine the size check with the existing damaged-file scan to avoid a second traversal and set of opens.

Before merging: testing (3) (runs on the systems it can change; it doesn't hold the recommendation)

  • L10 (minor) host/nn_fs.c:1174: Measure loading and frame pacing against the base on representative Windows and Linux systems, including Steam Deck: every listed compressed open now adds a read, and table initialization adds work on first use. (more on the line)
  • L11 (minor) nx2/make_game.py:799: Compare clean build times against the base on representative storage, including a cold scan: the new pass opens approximately 186,000 files, but the reported 106-second pack is not a comparable clean build. (more on the line)
  • L12 (minor) host/fs_sizes.c:80: Run the game on Windows with a clean dump and an oversized listed resource to verify the real synchronous handle read and warning; the only reported game run is Linux. (more on the line)

Checks: Still running: PR description / Description follows the template (pull_request_target).

More: does it help, other systems, switches, what was read

Does it help: Unproven overall. The reported Linux run produced the expected warning exactly once for one oversized texture, but the missing-file and builder paths have no reported passing run on this head. The claimed costs have no before-and-after timings.

Other systems: The hook runs on content file opens on Windows and Linux, including mod and overlay paths; the builder scans both unpacked and in-place RomFS folders. Windows handle and path behavior, concurrent dictionary initialization, build time, and loading or frame-pacing costs remain insufficiently verified.

Switches: None added, changed, or removed.

Reviewed: df0971b3d2 against 8dce60edcd: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, the complete diff, the new host checker, its table parser and decoder, the changed builder functions and new tests, and the OpenFile and platform file-handling code around the hook. Rechecked every changed file's diff. Skimmed surrounding build orchestration and existing test harnesses. docs/review-checklist.md and the adjacent Tooling checkout were absent; the full unchanged portions of the large changed files were not read.; nothing run (a code review).

Checked and fine:

  • Both commits record AI assistance.
  • No changed generated files, third-party files, renderer API, or player switches were found.
  • The table pointer is published before the atomic ready state, and the oversized-warning set is protected by a lock.
  • The new fixtures construct their resource data rather than committing game files.

Testing: Read-only review; no builds, scripts, or tests were run. The author reports a Linux game tour and one oversized overlay warning; Windows remains untested.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The new diagnostics can fail on supported Windows paths, miss changed or unreadable files, and stop a build on a damaged dictionary archive. They can also report files against a table the game does not use. The change names oversized and missing resources in the game and scans the RomFS during builds. The Linux game run demonstrates one oversized-file warning, but the added scan and runtime checks have correctness and measurement gaps. **`@fix` will do (11)** 1. **L1** `host/fs_sizes.c:59`: The table is reopened through hos_zs_read's narrow fopen, although OpenFile successfully opened it with UTF-8 to wide conversion and extended-length paths. (more on the line) 2. **L2** `host/fs_sizes.c:59`: This new runtime caller can enter hos_zs_decode concurrently with the mod or prompt readers. (more on the line) 3. **L3** `nx2/nup.py:797`: The dictionary archive parser unpacks SFAT nodes without checking that the node array is present. (more on the line) 4. **L4** `nx2/make_game.py:793`: The clean-check marker tracks the folder and tables but not the files checked. (more on the line) 5. **L5** `nx2/nup.py:845`: Unreadable or invalid tables are silently discarded, after which an empty result is treated as a clean scan and cached. (more on the line) 6. **L6** `nx2/make_game.py:801`: The scan compares each file with every table but this message says the game drops every reported file. (more on the line) 7. **L7** (minor) `host/fs_sizes.c:119`: The limit counts failed opens rather than distinct missing paths. (more on the line) 8. **L8** (minor) `host/fs_sizes.c:95`: restbl_key silently truncates paths to this 512-byte buffer, while guest paths can be longer. (more on the line) 9. **L9** `tests/test_fs_size_check.py:29`: The suite forces gcc and skips Windows, so a Linux setup with only Clang or an explicit CC fails or tests the wrong compiler, and the Windows implementation has no game-free coverage. (more on the line) 10. **L10** (its part an edit can do) `host/nn_fs.c:1174`: Avoid or batch the extra per-open read, or move table initialization off the first-use path. 11. **L11** (its part an edit can do) `nx2/make_game.py:799`: Combine the size check with the existing damaged-file scan to avoid a second traversal and set of opens. **Before merging: testing (3)** (runs on the systems it can change; it doesn't hold the recommendation) - **L10** (minor) `host/nn_fs.c:1174`: Measure loading and frame pacing against the base on representative Windows and Linux systems, including Steam Deck: every listed compressed open now adds a read, and table initialization adds work on first use. (more on the line) - **L11** (minor) `nx2/make_game.py:799`: Compare clean build times against the base on representative storage, including a cold scan: the new pass opens approximately 186,000 files, but the reported 106-second pack is not a comparable clean build. (more on the line) - **L12** (minor) `host/fs_sizes.c:80`: Run the game on Windows with a clean dump and an oversized listed resource to verify the real synchronous handle read and warning; the only reported game run is Linux. (more on the line) **Checks:** Still running: `PR description / Description follows the template (pull_request_target)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven overall. The reported Linux run produced the expected warning exactly once for one oversized texture, but the missing-file and builder paths have no reported passing run on this head. The claimed costs have no before-and-after timings. **Other systems:** The hook runs on content file opens on Windows and Linux, including mod and overlay paths; the builder scans both unpacked and in-place RomFS folders. Windows handle and path behavior, concurrent dictionary initialization, build time, and loading or frame-pacing costs remain insufficiently verified. **Switches:** None added, changed, or removed. **Reviewed:** df0971b3d286 against 8dce60edcd6d: Read AGENTS.md, CONTRIBUTING.md, the PR template, standards, the complete diff, the new host checker, its table parser and decoder, the changed builder functions and new tests, and the OpenFile and platform file-handling code around the hook. Rechecked every changed file's diff. Skimmed surrounding build orchestration and existing test harnesses. docs/review-checklist.md and the adjacent Tooling checkout were absent; the full unchanged portions of the large changed files were not read.; nothing run (a code review). **Checked and fine:** - Both commits record AI assistance. - No changed generated files, third-party files, renderer API, or player switches were found. - The table pointer is published before the atomic ready state, and the oversized-warning set is protected by a lock. - The new fixtures construct their resource data rather than committing game files. **Testing:** Read-only review; no builds, scripts, or tests were run. The author reports a Linux game tour and one oversized overlay warning; Windows remains untested. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.</sub>
host/fs_sizes.c Outdated
@ -0,0 +56,4 @@
for (char *p = path; *p; p++) if (*p == '\\') *p = '/'; /* (OpenFile's paths have '\', which fopen on Linux does not take) */
#endif
size_t n = 0;
uint8_t *raw = hos_zs_read(path, &n, 64u << 20);
Member

L1: The table is reopened through hos_zs_read's narrow fopen, although OpenFile successfully opened it with UTF-8 to wide conversion and extended-length paths. On Windows, a game folder containing characters outside the active code page or a long path can therefore disable all size diagnostics. Decode the already opened handle, and use the same UTF-8 and long-path handling for dictionary reads.

**L1**: The table is reopened through hos_zs_read's narrow fopen, although OpenFile successfully opened it with UTF-8 to wide conversion and extended-length paths. On Windows, a game folder containing characters outside the active code page or a long path can therefore disable all size diagnostics. Decode the already opened handle, and use the same UTF-8 and long-path handling for dictionary reads.
Member

L2: This new runtime caller can enter hos_zs_decode concurrently with the mod or prompt readers. In host/zs.c, the first thread sets the once flag before read_dicts writes ndicts and dicts; another thread reads those plain values without waiting, causing a data race and potentially failing to decode a valid dictionary-compressed table. Make dictionary initialization wait for completion and publish the finished data safely to every caller.

**L2**: This new runtime caller can enter hos_zs_decode concurrently with the mod or prompt readers. In host/zs.c, the first thread sets the once flag before read_dicts writes ndicts and dicts; another thread reads those plain values without waiting, causing a data race and potentially failing to decode a valid dictionary-compressed table. Make dictionary initialization wait for completion and publish the finished data safely to every caller.
host/fs_sizes.c Outdated
@ -0,0 +77,4 @@
uint8_t head[18];
OVERLAPPED ov = {0}; /* (at 0, whatever the handle's position: reads are positional) */
DWORD got = 0;
if (!ReadFile(h, head, sizeof head, &got, &ov) || !got) return 0;
Member

L12 (minor): Run the game on Windows with a clean dump and an oversized listed resource to verify the real synchronous handle read and warning; the only reported game run is Linux.

**L12** (minor): Run the game on Windows with a clean dump and an oversized listed resource to verify the real synchronous handle read and warning; the only reported game run is Linux.
host/fs_sizes.c Outdated
@ -0,0 +92,4 @@
}
if (!table_read() || ends_with(rel, ".mc")) return; /* (.mc: another compression, whose size its start does not say) */
char key[512];
uint32_t entry;
Member

L8 (minor): restbl_key silently truncates paths to this 512-byte buffer, while guest paths can be longer. A long listed path can be missed or matched against a different truncated key, producing an incorrect warning. Size the buffer for the supported guest path or reject truncation explicitly.

**L8** (minor): restbl_key silently truncates paths to this 512-byte buffer, while guest paths can be longer. A long listed path can be missed or matched against a different truncated key, producing an incorrect warning. Size the buffer for the supported guest path or reject truncation explicitly.
host/fs_sizes.c Outdated
@ -0,0 +116,4 @@
uint32_t entry;
if (!rel || !table_read() ||!ends_with(rel, ".zs") || !restbl_get(table, restbl_key(rel, key, sizeof key), &entry))
return;
const LONG n = InterlockedIncrement(&missing);
Member

L7 (minor): The limit counts failed opens rather than distinct missing paths. If the same listed missing resource is requested 20 times, it consumes the entire allowance and a different missing file responsible for a later crash is never named. Deduplicate missing paths before consuming the limit.

**L7** (minor): The limit counts failed opens rather than distinct missing paths. If the same listed missing resource is requested 20 times, it consumes the entire allowance and a different missing file responsible for a later crash is never named. Deduplicate missing paths before consuming the limit.
host/nn_fs.c Outdated
@ -1170,0 +1171,4 @@
the log (fs_sizes.c): the game drops it. Before the core is back, as the open: it reads the file's first 18 bytes */
{ void hos_fs_sizes_opened(const char *guest, const char *host, HANDLE h); /* fs_sizes.c */
void hos_fs_sizes_missing(const char *guest);
if (!want_write && h != INVALID_HANDLE_VALUE) hos_fs_sizes_opened(g, path, h);
Member

L10 (minor): Measure loading and frame pacing against the base on representative Windows and Linux systems, including Steam Deck: every listed compressed open now adds a read, and table initialization adds work on first use. The reported game tour establishes behavior but provides no comparison of these costs.

**L10** (minor): Measure loading and frame pacing against the base on representative Windows and Linux systems, including Steam Deck: every listed compressed open now adds a read, and table initialization adds work on first use. The reported game tour establishes behavior but provides no comparison of these costs.
nx2/make_game.py Outdated
@ -768,0 +790,4 @@
key.append("%s %d %d" % (name, st.st_size, st.st_mtime_ns))
key = "\n".join(key) + "\n"
if os.path.isfile(marker) and read_stamp(marker) == key:
return
Member

L4: The clean-check marker tracks the folder and tables but not the files checked. If an in-place RomFS file is later replaced with an oversized version while the table remains unchanged, the next build skips the scan and gives no warning. Invalidate the marker when checked files change, or rescan mutable RomFS folders.

**L4**: The clean-check marker tracks the folder and tables but not the files checked. If an in-place RomFS file is later replaced with an oversized version while the table remains unchanged, the next build skips the scan and gives no warning. Invalidate the marker when checked files change, or rescan mutable RomFS folders.
nx2/make_game.py Outdated
@ -768,0 +796,4 @@
print("Your game files have %d resource size tables (%s): the game reads only its own version's. Game files of another "
"version unpacked over these (a base dump and an update) can be bigger than the game allows, and the game then stops "
"when it needs one." % (len(tables), ", ".join(tables)), flush=True)
_, bigger = nup.size_table_check(romfs, file_progress("checked"))
Member

L11 (minor): Compare clean build times against the base on representative storage, including a cold scan: the new pass opens approximately 186,000 files, but the reported 106-second pack is not a comparable clean build.

**L11** (minor): Compare clean build times against the base on representative storage, including a cold scan: the new pass opens approximately 186,000 files, but the reported 106-second pack is not a comparable clean build.
nx2/make_game.py Outdated
@ -768,0 +798,4 @@
"when it needs one." % (len(tables), ", ".join(tables)), flush=True)
_, bigger = nup.size_table_check(romfs, file_progress("checked"))
if bigger:
print("%d game file%s bigger than %s entr%s in the game's resource size table: the game leaves %s out, and stops when it "
Member

L6: The scan compares each file with every table but this message says the game drops every reported file. With an old base table and the current update table, a file can exceed the old entry while fitting the table the game actually opens, leading players to redump a valid installation. Select the game's active table for definitive warnings, or clearly label comparisons against other tables as inconclusive.

**L6**: The scan compares each file with every table but this message says the game drops every reported file. With an old base table and the current update table, a file can exceed the old entry while fitting the table the game actually opens, leading players to redump a valid installation. Select the game's active table for definitive warnings, or clearly label comparisons against other tables as inconclusive.
nx2/nup.py Outdated
@ -767,0 +794,4 @@
return {}
size, count = struct.unpack_from("<HH", p, head + 4)
found = {}
for i in range(count):
Member

L3: The dictionary archive parser unpacks SFAT nodes without checking that the node array is present. A valid zstd frame containing a truncated SARC with an SFAT header and nonzero node count raises struct.error and aborts the build, although this check is meant to be a warning. Validate the header, node and data bounds and handle malformed dictionaries without stopping the build.

**L3**: The dictionary archive parser unpacks SFAT nodes without checking that the node array is present. A valid zstd frame containing a truncated SARC with an SFAT header and nonzero node count raises struct.error and aborts the build, although this check is meant to be a warning. Validate the header, node and data bounds and handle malformed dictionaries without stopping the build.
nx2/nup.py Outdated
@ -767,0 +842,4 @@
return [], []
dictionaries = zs_dictionaries(romfs)
read = [(name, read_size_table(os.path.join(romfs, *SIZE_TABLES, name), dictionaries)) for name in tables]
read = [(name, t) for name, t in read if t]
Member

L5: Unreadable or invalid tables are silently discarded, after which an empty result is treated as a clean scan and cached. For example, a table needing a missing dictionary produces no file warnings and writes the success marker. Report the failed table and do not cache the scan as clean unless every intended table was read.

**L5**: Unreadable or invalid tables are silently discarded, after which an empty result is treated as a clean scan and cached. For example, a table needing a missing dictionary produces no file warnings and writes the success marker. Report the failed table and do not cache the scan as clean unless every intended table was read.
@ -0,0 +26,4 @@
import zlib
from pathlib import Path
RUN_ALL_ARGS = ["--cc", "gcc"]
Member

L9: The suite forces gcc and skips Windows, so a Linux setup with only Clang or an explicit CC fails or tests the wrong compiler, and the Windows implementation has no game-free coverage. Use the runner's {cc} and provide a Windows fixture that exercises the real handle and path behavior.

**L9**: The suite forces gcc and skips Windows, so a Linux setup with only Clang or an explicit CC fails or tests the wrong compiler, and the Windows implementation has no game-free coverage. Use the runner's {cc} and provide a Windows fixture that exercises the real handle and path behavior.
Author
Owner
@fix
BeanBot force-pushed fix/fs-size-table-check from df0971b3d2
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 6s
PR description / Description follows the template (pull_request_target) Successful in 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 21s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 22s
CI / Website build and checks (pull_request) Failing after 24s
Third-party parts / As their notes say (pull_request) Successful in 27s
to a4dfda1822
Some checks failed
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Website build and checks (pull_request) Failing after 21s
CI / Conventional Commit title (pull_request) Successful in 27s
PR description / Description follows the template (pull_request_target) Successful in 34s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 42s
CI / Workflow lint (actionlint) (pull_request) Successful in 44s
Third-party parts / As their notes say (pull_request) Successful in 46s
2026-11-22 01:34:51 +00:00
Compare
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The Linux run shows the oversized-resource warning working, but the runtime and builder costs remain unmeasured, and the Windows path has not been verified in game. Recommend approval; not approved on the forge.

What @fix changed
I changed this pull request: the new head is a4dfda1822. I rebased it onto main (a2dc538590). I edited its description to match the change.

Changed

  • Runtime table and dictionary paths: host/fs_sizes.c:52 decodes the opened table handle; host/zs.c:26 reads dictionaries using UTF-8 and extended-length Windows paths.
  • Concurrent dictionary initialization: host/zs.c:126 serializes initialization and publishes the completed dictionaries under a lock.
  • Malformed dictionary archives: nx2/nup.py:780 validates SARC headers, node arrays and data bounds; tests/test_builder_size_table.py:173 covers a truncated node array.
  • Stale clean-check marker: nx2/make_game.py:772 rescans mutable RomFS files on each build and removes obsolete markers.
  • Unreadable size tables: nx2/nup.py:841 reports unreadable table names to nx2/make_game.py:794, which logs them; scans are no longer cached as clean.
  • Cross-table warning: nx2/make_game.py:798 labels comparisons as inconclusive unless the game uses the table and notes that mods can modify it.
  • Compiler selection and Windows fixture: tests/test_fs_size_check.py:31 uses the runner's compiler and exercises real Windows handles with Unicode and long paths. The fixture was not run.
  • Distinct missing paths: host/fs_sizes.c:132 deduplicates missing keys before consuming the 20-path allowance.
  • Long resource keys: host/fs_sizes.c:96 enlarges the key buffer and rejects paths that would be truncated; tests/test_fs_size_check.py:218 covers a path longer than 512 bytes.

Changed in part (the rest is for the author)

  • Runtime read cost: host/nn_fs.c:1279 reuses and assembles the game's frame-header reads instead of issuing a read per compressed open. The author must measure loading and frame pacing against the base on representative Windows and Linux systems, including Steam Deck.

Not done

  • Builder scan cost: The size and damaged-file scans still need to share a traversal and file opens. The author must also compare clean build times against the base on representative storage, including a cold scan.

Nothing was built or run: the checks run again on the new head.

The change names missing and oversized game resources to make crashes easier to diagnose. It adds table initialization and file-checking work at runtime, plus a scan of the RomFS during builds.

Before merging: testing (3) (runs on the systems it can change; it doesn't hold the recommendation)

  • L10 (minor) host/nn_fs.c:1174: Measure loading and frame pacing against the base on representative Windows and Linux systems, including Steam Deck: every listed compressed open now adds a read, and table initialization adds work on first use. The reported game tour establishes behavior but provides no comparison of these costs.
  • L11 (minor) nx2/make_game.py:799: Compare clean build times against the base on representative storage, including a cold scan: the new pass opens approximately 186,000 files, but the reported 106-second pack is not a comparable clean build.
  • L12 (minor) host/fs_sizes.c:80: Run the game on Windows with a clean dump and an oversized listed resource to verify the real synchronous handle read and warning; the only reported game run is Linux.

Checks: they run again on this head (Guide screenshots / Guide images and local UI source review (pull_request), CI / Website build and checks (pull_request) failed on the last one); a failure shows on the pull request.

Also noticed (2; not asked for, not blocking)
  • The pull request description still describes an extra 18-byte read per compressed open and a clean-check marker, although the revised code reuses game reads and removes the marker.
  • The earlier Linux game run predates the revised compressed-header read path.
More: does it help, other systems, switches, what was read

Does it help: Unproven overall. The reported Linux run found one injected oversized texture and logged it exactly once; a clean tour produced no new warnings. Comparable runtime and clean-build cost measurements are missing.

Other systems: The runtime check affects Windows and Linux file reads, including Steam Deck; the builder scan affects storage on both platforms. Linux gameplay was reported, but Windows behavior and comparative costs remain unverified.

Switches: None added, changed or removed.

Reviewed: a4dfda1822 against a2dc538590: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, host/fs_sizes.c and host/zs.c; inspected the relevant portions of host/nn_fs.c, nx2/nup.py and nx2/make_game.py and the main code diff. The remaining changed files and tests were not read in full.; nothing run (a code review).

Checked and fine:

  • Compressed-resource checks use header bytes from the game's reads instead of issuing a separate read per open.
  • The reported Linux tour and injected oversized texture provide evidence for the runtime warning.

Testing: No tests were run during this read-only review. CI has not yet run on this head; the reported Windows game run and comparative measurements remain outstanding.

Overlaps and merge order: none found


Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The Linux run shows the oversized-resource warning working, but the runtime and builder costs remain unmeasured, and the Windows path has not been verified in game. Recommend approval; not approved on the forge. **What `@fix` changed** I changed this pull request: the new head is a4dfda18225b. I rebased it onto `main` (a2dc53859018). I edited its description to match the change. **Changed** - **Runtime table and dictionary paths**: host/fs_sizes.c:52 decodes the opened table handle; host/zs.c:26 reads dictionaries using UTF-8 and extended-length Windows paths. - **Concurrent dictionary initialization**: host/zs.c:126 serializes initialization and publishes the completed dictionaries under a lock. - **Malformed dictionary archives**: nx2/nup.py:780 validates SARC headers, node arrays and data bounds; tests/test_builder_size_table.py:173 covers a truncated node array. - **Stale clean-check marker**: nx2/make_game.py:772 rescans mutable RomFS files on each build and removes obsolete markers. - **Unreadable size tables**: nx2/nup.py:841 reports unreadable table names to nx2/make_game.py:794, which logs them; scans are no longer cached as clean. - **Cross-table warning**: nx2/make_game.py:798 labels comparisons as inconclusive unless the game uses the table and notes that mods can modify it. - **Compiler selection and Windows fixture**: tests/test_fs_size_check.py:31 uses the runner's compiler and exercises real Windows handles with Unicode and long paths. The fixture was not run. - **Distinct missing paths**: host/fs_sizes.c:132 deduplicates missing keys before consuming the 20-path allowance. - **Long resource keys**: host/fs_sizes.c:96 enlarges the key buffer and rejects paths that would be truncated; tests/test_fs_size_check.py:218 covers a path longer than 512 bytes. **Changed in part (the rest is for the author)** - **Runtime read cost**: host/nn_fs.c:1279 reuses and assembles the game's frame-header reads instead of issuing a read per compressed open. The author must measure loading and frame pacing against the base on representative Windows and Linux systems, including Steam Deck. **Not done** - **Builder scan cost**: The size and damaged-file scans still need to share a traversal and file opens. The author must also compare clean build times against the base on representative storage, including a cold scan. Nothing was built or run: the checks run again on the new head. The change names missing and oversized game resources to make crashes easier to diagnose. It adds table initialization and file-checking work at runtime, plus a scan of the RomFS during builds. **Before merging: testing (3)** (runs on the systems it can change; it doesn't hold the recommendation) - **L10** (minor) `host/nn_fs.c:1174`: Measure loading and frame pacing against the base on representative Windows and Linux systems, including Steam Deck: every listed compressed open now adds a read, and table initialization adds work on first use. The reported game tour establishes behavior but provides no comparison of these costs. - **L11** (minor) `nx2/make_game.py:799`: Compare clean build times against the base on representative storage, including a cold scan: the new pass opens approximately 186,000 files, but the reported 106-second pack is not a comparable clean build. - **L12** (minor) `host/fs_sizes.c:80`: Run the game on Windows with a clean dump and an oversized listed resource to verify the real synchronous handle read and warning; the only reported game run is Linux. **Checks:** they run again on this head (`Guide screenshots / Guide images and local UI source review (pull_request)`, `CI / Website build and checks (pull_request)` failed on the last one); a failure shows on the pull request. <details> <summary>Also noticed (2; not asked for, not blocking)</summary> - The pull request description still describes an extra 18-byte read per compressed open and a clean-check marker, although the revised code reuses game reads and removes the marker. - The earlier Linux game run predates the revised compressed-header read path. </details> <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven overall. The reported Linux run found one injected oversized texture and logged it exactly once; a clean tour produced no new warnings. Comparable runtime and clean-build cost measurements are missing. **Other systems:** The runtime check affects Windows and Linux file reads, including Steam Deck; the builder scan affects storage on both platforms. Linux gameplay was reported, but Windows behavior and comparative costs remain unverified. **Switches:** None added, changed or removed. **Reviewed:** a4dfda18225b against a2dc53859018: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, host/fs_sizes.c and host/zs.c; inspected the relevant portions of host/nn_fs.c, nx2/nup.py and nx2/make_game.py and the main code diff. The remaining changed files and tests were not read in full.; nothing run (a code review). **Checked and fine:** - Compressed-resource checks use header bytes from the game's reads instead of issuing a separate read per open. - The reported Linux tour and injected oversized texture provide evidence for the runtime warning. **Testing:** No tests were run during this read-only review. CI has not yet run on this head; the reported Windows game run and comparative measurements remain outstanding. **Overlaps and merge order:** none found </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.</sub>
dazemc left a comment

Read of a4dfda18 (on main's head, WIP; game-free checks only, no game run from me). The gate, the host comparison and the not-found path hold up. One builder test fails on this head, and the cause is a real gap in the check.

1. tests/test_builder_size_table.py fails on a4dfda18: the builder skips any .zs frame shorter than 18 bytes.

$ python -I -B tests/test_builder_size_table.py
FAIL: test_the_build_says_them_once_checked
  self.assertEqual(build()[1:], ["  Model/Big.bfres.zs: 90 bytes, its entry 50"])
AssertionError: Lists differ: [] != ['  Model/Big.bfres.zs: 90 bytes, its entry 50']

nx2/nup.py:44 (frame_content_size) returns None for len(head) < 18, but the test's zs(bytes(90)) is a 17-byte frame (single-segment, one-byte FCS at offset 5), and size_table_check reads exactly 18 bytes (nup.py:879) and treats None as "states no size". So a listed .zs whose whole frame is 17 bytes or less is never checked, and the test's 90-vs-50 case is silently skipped. The comparison itself is fine (size > entry); the gate is the off-by-one. A file under 18 bytes read whole is a complete frame, not a truncated header: requiring only the bytes the header uses (len(head) >= 5 and at + n <= len(head)) instead of >= 18 makes all six tests pass here (I tried that two-line change in a scratch checkout; nothing pushed). If the helper's < 18 must stay for its two other callers (nup.py:302, 733), the new caller needs its own parse. The host is not affected: stated_size asks zstd's ZSTD_getFrameContentSize for the game's read, so the game would name exactly the file the builder misses.

CI will not catch this on the PR: .forgejo/workflows/ci.yml runs Python source checks only on workflow_dispatch (if: github.event_name == 'workflow_dispatch'), and the run for a4dfda18 shows them skipped. The body's "passing here is up to CI" needs a local mise run test, or at least these two files.

2. The not-found path is right; two small wording nits.
hos_fs_sizes_missing (fs_sizes.c:130) runs before the existing R_PATH_NOT_FOUND return (nn_fs.c:1176), so the error code is unchanged: only read-only opens, only listed .zs, distinct by key, capped at 20. (a) Any CreateFileA failure is logged as "not found", including a sharing violation or access denied, where the file is there; the old line with those words was trace-only, this one is a WARN. (b) With exactly 20 distinct missing files, the 20th still says "(more are not named)" and there are none more.

3. No off-by-one or overflow in either comparison.
Host: size <= entry (fs_sizes.c:101) is "a file exactly the entry's size fits"; size is uint64_t and entry uint32_t; a frame that states no size (error/unknown) and a zero-length non-.zs become 0, so they don't fire; .mc is out. restbl_parse validates the exact table length in 64-bit arithmetic (restbl.c:49), so a malformed table is rejected rather than misread. The builder's size > entry matches. The test's own frame() and zstandard 0.25.0 (the pinned version) agree on the 90-byte case.

4. Behavior for valid files: no change I can find.
The table is read once from the handle OpenFile already opened, at open time, at offset 0; every game read goes through read_at with its own OVERLAPPED offset, so the handle's position cannot matter, and only warnings are added. The new read hook (nn_fs.c:1279-1292) takes handle_lock for the head and never the save lock for a content: handle; content_rel rejects save: and other mounts, so #607's save staging and #2154's delete path are untouched — no textual or lock interaction, and #2154's test_fs_delete_dir.py does not collide with this PR's tests. The zs.c dictionary lock (it replaces the once CAS, and sets dicts_read after a read that can fail) and the long-path _wfopen are fixes, not changes for ordinary paths. test_fs_size_check.py, test_vcore_fs_open.py and test_damaged_rom_files.py pass here. (test_fs_save_commit.py does not compile on this machine on main either — hos.h's memset/memcpy without <string.h> with this GCC — so I could not use it; not this PR's doing.)

5. Test gap: the read_at head assembly is covered only in-game.
tests/test_fs_size_check.py calls hos_fs_sizes_opened/hos_fs_sizes_read itself over the real fs_sizes.c/zs.c/restbl.c, and the other harnesses stub those calls, so nn_fs.c's new size_head/size_head_mask code — partial reads, off < 18, the contiguous-prefix loop — has no game-free test. It reads right to me (bytes at size_head + off, mask, prefix until a gap), but it is the most intricate new host code and the body's Linux run only exercises the one-shot 18-byte read. A fixture driving the real read_at with two reads (10 + 8) would settle it.

6. Build cost. With the marker removed, every build re-walks the RomFS and opens about 186,000 .zs files; the 106 s pack is not a clean build, and the Measurements has no before/after. The earlier review asked and the head answered with the cost, not a number; one cold build time on a slow disk would let the PR say "about N s".

The "fails on main" claim is true only in the trivial sense the body gives (neither function exists there); the meaningful half — passing here — is what the builder test does not do yet. No approval and no claim; the Windows game run in Still to test is the hardware box I cannot settle.

**Read of `a4dfda18` (on `main`'s head, WIP; game-free checks only, no game run from me).** The gate, the host comparison and the not-found path hold up. One builder test **fails on this head**, and the cause is a real gap in the check. **1. `tests/test_builder_size_table.py` fails on `a4dfda18`: the builder skips any `.zs` frame shorter than 18 bytes.** ``` $ python -I -B tests/test_builder_size_table.py FAIL: test_the_build_says_them_once_checked self.assertEqual(build()[1:], [" Model/Big.bfres.zs: 90 bytes, its entry 50"]) AssertionError: Lists differ: [] != [' Model/Big.bfres.zs: 90 bytes, its entry 50'] ``` `nx2/nup.py:44` (`frame_content_size`) returns `None` for `len(head) < 18`, but the test's `zs(bytes(90))` is a **17-byte** frame (single-segment, one-byte FCS at offset 5), and `size_table_check` reads exactly 18 bytes (`nup.py:879`) and treats `None` as "states no size". So a listed `.zs` whose whole frame is 17 bytes or less is never checked, and the test's 90-vs-50 case is silently skipped. The comparison itself is fine (`size > entry`); the gate is the off-by-one. A file under 18 bytes read whole is a *complete* frame, not a truncated header: requiring only the bytes the header uses (`len(head) >= 5` and `at + n <= len(head)`) instead of `>= 18` makes all six tests pass here (I tried that two-line change in a scratch checkout; nothing pushed). If the helper's `< 18` must stay for its two other callers (`nup.py:302`, `733`), the new caller needs its own parse. The host is not affected: `stated_size` asks zstd's `ZSTD_getFrameContentSize` for the game's read, so the game would name exactly the file the builder misses. CI will not catch this on the PR: `.forgejo/workflows/ci.yml` runs `Python source checks` only on `workflow_dispatch` (`if: github.event_name == 'workflow_dispatch'`), and the run for `a4dfda18` shows them skipped. The body's "passing here is up to CI" needs a local `mise run test`, or at least these two files. **2. The not-found path is right; two small wording nits.** `hos_fs_sizes_missing` (`fs_sizes.c:130`) runs before the existing `R_PATH_NOT_FOUND` return (`nn_fs.c:1176`), so the error code is unchanged: only read-only opens, only listed `.zs`, distinct by key, capped at 20. (a) Any `CreateFileA` failure is logged as "not found", including a sharing violation or access denied, where the file is there; the old line with those words was trace-only, this one is a WARN. (b) With exactly 20 distinct missing files, the 20th still says "(more are not named)" and there are none more. **3. No off-by-one or overflow in either comparison.** Host: `size <= entry` (`fs_sizes.c:101`) is "a file exactly the entry's size fits"; `size` is `uint64_t` and `entry` `uint32_t`; a frame that states no size (error/unknown) and a zero-length non-`.zs` become 0, so they don't fire; `.mc` is out. `restbl_parse` validates the exact table length in 64-bit arithmetic (`restbl.c:49`), so a malformed table is rejected rather than misread. The builder's `size > entry` matches. The test's own `frame()` and zstandard 0.25.0 (the pinned version) agree on the 90-byte case. **4. Behavior for valid files: no change I can find.** The table is read once from the handle `OpenFile` already opened, at open time, at offset 0; every game read goes through `read_at` with its own `OVERLAPPED` offset, so the handle's position cannot matter, and only warnings are added. The new read hook (`nn_fs.c:1279-1292`) takes `handle_lock` for the head and never the save lock for a `content:` handle; `content_rel` rejects `save:` and other mounts, so #607's save staging and #2154's delete path are untouched — no textual or lock interaction, and #2154's `test_fs_delete_dir.py` does not collide with this PR's tests. The `zs.c` dictionary lock (it replaces the `once` CAS, and sets `dicts_read` after a read that can fail) and the long-path `_wfopen` are fixes, not changes for ordinary paths. `test_fs_size_check.py`, `test_vcore_fs_open.py` and `test_damaged_rom_files.py` pass here. (`test_fs_save_commit.py` does not compile on this machine on **main** either — `hos.h`'s `memset`/`memcpy` without `<string.h>` with this GCC — so I could not use it; not this PR's doing.) **5. Test gap: the `read_at` head assembly is covered only in-game.** `tests/test_fs_size_check.py` calls `hos_fs_sizes_opened`/`hos_fs_sizes_read` itself over the real `fs_sizes.c`/`zs.c`/`restbl.c`, and the other harnesses stub those calls, so `nn_fs.c`'s new `size_head`/`size_head_mask` code — partial reads, `off < 18`, the contiguous-prefix loop — has no game-free test. It reads right to me (bytes at `size_head + off`, mask, prefix until a gap), but it is the most intricate new host code and the body's Linux run only exercises the one-shot 18-byte read. A fixture driving the real `read_at` with two reads (10 + 8) would settle it. **6. Build cost.** With the marker removed, every build re-walks the RomFS and opens about 186,000 `.zs` files; the 106 s pack is not a clean build, and the Measurements has no before/after. The earlier review asked and the head answered with the cost, not a number; one cold build time on a slow disk would let the PR say "about N s". The "fails on `main`" claim is true only in the trivial sense the body gives (neither function exists there); the meaningful half — passing here — is what the builder test does not do yet. No approval and no claim; the Windows game run in Still to test is the hardware box I cannot settle.
HumanBean force-pushed fix/fs-size-table-check from a4dfda1822
Some checks failed
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Website build and checks (pull_request) Failing after 21s
CI / Conventional Commit title (pull_request) Successful in 27s
PR description / Description follows the template (pull_request_target) Successful in 34s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 42s
CI / Workflow lint (actionlint) (pull_request) Successful in 44s
Third-party parts / As their notes say (pull_request) Successful in 46s
to 491eb6b8d8
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 14s
CI / Workflow lint (actionlint) (pull_request) Successful in 17s
Third-party parts / As their notes say (pull_request) Successful in 20s
PR description / Description follows the template (pull_request_target) Successful in 11s
CI / Website build and checks (pull_request) Failing after 44s
2026-11-22 16:29:21 +00:00
Compare
Author
Owner

Thanks, all six read and acted on; new head 491eb6b8 (two commits, test 9832521d and fix; BeanBot's a4dfda18 folded into the fix). Code only, nothing run yet.

  1. Fixed. frame_content_size (nx2/nup.py:42) now needs only the bytes the frame's descriptor uses (len(head) >= 5, at + n <= len(head)), so a whole file under 18 bytes is checked. is_packed and still_in_nup_frame are fine with it (a short head there is a complete header too). New test_a_file_shorter_than_a_header_read; the 90-vs-50 build case is covered by it.
  2. Both fixed. (a) nn_fs.c takes GetLastError() after CreateFileA; only ERROR_FILE_NOT_FOUND / ERROR_PATH_NOT_FOUND (ENOENT / ENOTDIR through host/posix) call hos_fs_sizes_missing; the trace line says "could not be opened (error N)" otherwise. The game still gets R_PATH_NOT_FOUND. (b) The 20th line has no suffix; a 21st distinct missing file logs fs: more files the size table lists are not found: only the first 20 are named, once. Tests cover exactly 20 (no line) and more.
  3. and 4. Thanks for checking; nothing changed there.
  4. Done. The head assembly moved into hos_fs_sizes_read in host/fs_sizes.c; read_at is one call. The fixture drives the real code with split, out-of-order and gapped reads (10+8, 6+12 then 0+6, a gap filled last, a byte never read, a repeat, reads past 18 only) and a 15-byte whole file.
  5. Not yet. The size check can't share the damaged-file scan: that one runs once per unpack (its stamp), normally opens nothing (it reads the extraction's head list) and never runs for --romfs / --romfs-in-place. So the per-build cost is the size check's own walk. I'll time a clean build, cold and warm, against main and put the numbers in Measurements; if it's noticeable, the fix is a once-per-unpack marker for builder-unpacked RomFS keyed on the unpack stamp and the tables' size and mtime.

The Linux game runs will be redone on this head, with the Windows run through the Test Farm.

Thanks, all six read and acted on; new head 491eb6b8 (two commits, test 9832521d and fix; BeanBot's a4dfda18 folded into the fix). Code only, nothing run yet. 1. **Fixed.** `frame_content_size` (`nx2/nup.py:42`) now needs only the bytes the frame's descriptor uses (`len(head) >= 5`, `at + n <= len(head)`), so a whole file under 18 bytes is checked. `is_packed` and `still_in_nup_frame` are fine with it (a short head there is a complete header too). New `test_a_file_shorter_than_a_header_read`; the 90-vs-50 build case is covered by it. 2. **Both fixed.** (a) `nn_fs.c` takes `GetLastError()` after `CreateFileA`; only ERROR_FILE_NOT_FOUND / ERROR_PATH_NOT_FOUND (ENOENT / ENOTDIR through host/posix) call `hos_fs_sizes_missing`; the trace line says "could not be opened (error N)" otherwise. The game still gets `R_PATH_NOT_FOUND`. (b) The 20th line has no suffix; a 21st distinct missing file logs `fs: more files the size table lists are not found: only the first 20 are named`, once. Tests cover exactly 20 (no line) and more. 3. and 4. Thanks for checking; nothing changed there. 5. **Done.** The head assembly moved into `hos_fs_sizes_read` in `host/fs_sizes.c`; `read_at` is one call. The fixture drives the real code with split, out-of-order and gapped reads (10+8, 6+12 then 0+6, a gap filled last, a byte never read, a repeat, reads past 18 only) and a 15-byte whole file. 6. **Not yet.** The size check can't share the damaged-file scan: that one runs once per unpack (its stamp), normally opens nothing (it reads the extraction's head list) and never runs for `--romfs` / `--romfs-in-place`. So the per-build cost is the size check's own walk. I'll time a clean build, cold and warm, against main and put the numbers in Measurements; if it's noticeable, the fix is a once-per-unpack marker for builder-unpacked RomFS keyed on the unpack stamp and the tables' size and mtime. The Linux game runs will be redone on this head, with the Windows run through the Test Farm.
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 14s
CI / Workflow lint (actionlint) (pull_request) Successful in 17s
Third-party parts / As their notes say (pull_request) Successful in 20s
PR description / Description follows the template (pull_request_target) Successful in 11s
CI / Website build and checks (pull_request) Failing after 44s
This pull request has changes conflicting with the target branch.
  • docs/dev/reference/mods.md
  • host/nn_fs.c
  • host/zs.c
  • nx2/build.py
  • nx2/make_game.py
  • nx2/nup.py
  • tests/test_damaged_rom_files.py
  • tests/test_fs_save_commit.py
  • tests/test_mods_size_table.py
  • tests/test_mods_sizes.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/fs-size-table-check:HumanBean-fix/fs-size-table-check'
git switch 'HumanBean-fix/fs-size-table-check'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2173
No description provided.