Skip to content

packing/nup: read meta blocks that nup numbers one too low, and leave out a NACP that is not 0x4000 bytes - #2879

Closed
oliverames wants to merge 1 commit into
seedds:mainfrom
oliverames:nx18-nup-control-data
Closed

oliverames wants to merge 1 commit into
seedds:mainfrom
oliverames:nx18-nup-control-data

Conversation

@oliverames

Copy link
Copy Markdown
Contributor

Requested by Oliver · project thread

What and why

Credit: this is kencalx's work from the NX18 fork, ported onto current main. kencalx is a co-author on the commit, and every measurement below that is not marked as mine is theirs.

Symptom: a NUP made by the nup tool since its PR #20 (merged 2026-11-04) writes every meta record's type one too low (NPDM 0, NACP 1, icon 2, localized icons 9). pack_nup.py read SPEC section 5's numbers, so for such a file it saved the icon JPEG as control.nacp and the display version as icon.jpg: a blank game name, a random language list and no icon. Separately, a NACP record that is not 0x4000 bytes was saved as control.nacp as it was.

Fix: Package.meta() now tells a shifted block and reads every type one up. The records decide first (the 0x4000-byte NACP at type 1 or 2, else a JPEG or PNG icon at 2 or 3); only when they cannot tell does nup's PR #32 rule decide (a record of type 0, or one of type 7 that is not 32 bytes, the build ID's size). A block from an older nup is read as it is. control() says in one line per package that it read a block one type up, and leaves out a NACP record of another size with a line; a base game's good NACP still fills in for an update that lacks one. The lines also show in a build with a profile, which otherwise packs quietly (pack_version takes a note= callback, and the NSP script's survey passes its own output to control()). docs/development.md and the README say it.

Tests: synthetic shifted and SPEC-numbered blocks, a type 7 record of 32 bytes and one of another size, shifted localized icons, wrong-size NACPs, a standalone update whose own bad NACP falls back to the base record, the line said once per package, and the build and the survey saying it. test_nsp_nup.py passes (53 tests, 12 new) with backports.zstd, lz4 and capstone installed; test_docs passes. On a Mac (M2 Pro, macOS 27.3) test_nsp_nup.py passes too (53 tests). test_nsp_mac_app.py has 23 errors both with and without this change on Linux (it needs macOS). Not checked: the Mac app build, and a real NUP written by nup (the claim about nup's PR #20 and #32 is NX18's, not re-checked).

Ported from NX18 (kencalx/NX18), by hand since the code moved: 3acdfeacb kencalx/NX18@3acdfeacb, with the follow-up fixes in 0d343ee5d and 9fffe70e0 folded in. Left out: everything about NX archive input (scripts/pack_nx.py and its tests, the title.txt and icon.edited.jpg files, the app name from an NX's display title).

Checked

  • Tests: on a Mac (M2 Pro, macOS 27.3): test_nsp_nup.py, 53 tests, all pass; on Linux the same with test_docs. Not checked: test_nsp_mac_app.py (the Mac app build), and a real NUP written by nup.
  • Games run, with title ID and version: none for this PR; the game observations above are NX18's.
  • Devices and OS: M2 Pro, macOS 27.3, Xcode 27.3 beta. No iPhone or iPad run.
  • scripts/regress.py check --games: not run.

Docs

  • The finding is in its game note or its docs/reference/<subsystem>.md entry: not applicable, a small internal fix with no symptom a player sees
  • A chain tool changed: not applicable, no chain tool changed
  • No game files, keys or data extracted from a game in the change or the attachments

🤖 Generated with Claude Code

https://claude.ai/code/session_01RcRaRTbNVNsBJcfGqFidW1

Upstream nup PR seedds#20 started its TLV enum at 0 instead of SPEC §5's
1. This wrote JPEG icons at the NACP type and display versions at
the icon type. Normalize affected blocks at the shared reader.
Prefer NACP and icon content, then use the markers described in
upstream nup PR seedds#32. Preserve correctly numbered control data when
it appears with shift markers.

Reject NACP payloads of any size other than 0x4000 in the same
reader. Package scanning previously trusted the ID fields of some
truncated or oversized payloads, which could reject valid DLC.
Filter those payloads before either scanning or extraction uses them.

Verified with the upstream writer and a one-line enum correction,
real shifted and SPEC-numbered archives, and synthetic regression
cases for wrongly sized NACPs and valid titles beginning with META.

Ported from kencalx/NX18 (3acdfeacb, 0d343ee5d, 9fffe70e0).
PR seedds#2879

Co-authored-by: Oliver Ames <7366664+oliverames@users.noreply.github.com>
Co-authored-by: kenCalx <105067885+kencalx@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@seedds
seedds force-pushed the nx18-nup-control-data branch from bdbacad to 2a61623 Compare November 20, 2026 17:31
@seedds
seedds marked this pull request as ready for review November 20, 2026 17:31
@github-actions github-actions Bot added packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers tools Tools and scripts (dm/tools, scripts) docs Documentation labels Nov 20, 2026
seedds added a commit that referenced this pull request Nov 21, 2026
Upstream nup PR #20 started its TLV enum at 0 instead of SPEC §5's
1. This wrote JPEG icons at the NACP type and display versions at
the icon type. Normalize affected blocks at the shared reader.
Prefer NACP and icon content, then use the markers described in
upstream nup PR #32. Preserve correctly numbered control data when
it appears with shift markers.

Reject NACP payloads of any size other than 0x4000 in the same
reader. Package scanning previously trusted the ID fields of some
truncated or oversized payloads, which could reject valid DLC.
Filter those payloads before either scanning or extraction uses them.

Verified with the upstream writer and a one-line enum correction,
real shifted and SPEC-numbered archives, and synthetic regression
cases for wrongly sized NACPs and valid titles beginning with META.

Ported from kencalx/NX18 (3acdfeacb, 0d343ee5d, 9fffe70e0).
PR #2879

Co-authored-by: Oliver Ames <7366664+oliverames@users.noreply.github.com>
Co-authored-by: kenCalx <105067885+kencalx@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@seedds

seedds commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thanks, Oliver and kenCalx, for tracing the NUP metadata bug and bringing the fix over. It’s on main in a1a81f7. The reader handles the shifted metadata and discards wrong-size control records before scanning or extraction can use them.

All 62 NUP tests passed on GitHub. The failing checks reproduced on the original base, and the affected checks passed locally after rebasing onto main’s separate fixes. The writer correction is still pending upstream, so existing archives continue to be handled by the reader.

@seedds seedds closed this Nov 21, 2026
@oliverames
oliverames deleted the nx18-nup-control-data branch November 28, 2026 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants