Repository navigation
Conversation
…ding the shaders (igawa6#561) Pokémon Legends: Z-A 2.0.2 stopped at Finding the shaders on a phone with "struct.error: unpack_from requires a buffer of at least 8725344222 bytes", and the card offered Retry, which failed the same way every time. The update's data.trpfs had its right size but a garbled index: the update dump was damaged. The importer compared an NCZ's bytes with its CNMT record, but never a plain NCA's, so the damage went into the .nup unnoticed. The importer now checks every plain NCA it writes from against the NCA's own hash layers (dm/peanuts/import/nx_verify.c): the fs header against its SHA-256 in the NCA header, the RomFS's IVFC levels and the ExeFS's hash table from the master hash down when the NCA is opened, and each data block as the writer reads it. A patch's RomFS is checked through the patched image, and the base bytes it reads against the base's own levels, so the file named is the one that is damaged. The NCA's size is compared with its CNMT record and its header, and a container that ends early is refused before its titles are read. A mismatch stops the import with "<file>: the update v393216 is damaged or incomplete: ...", and the card says which file it is (the game, its update or a DLC), that nothing was changed and what to do, with the game's sheet and no Retry (dev.peanuts.build.DamagedFile, FILE_DAMAGED). Hashing each NCA whole against its CNMT SHA-256, as an NCZ is, would read every byte a second time. The hash layers cost only the hashing of bytes the writer reads anyway, spread over its worker threads. A .nup imported before this still reaches the shader split. Its FlatBuffers readers (trpfs_jobs, trinity_shaders) check every offset against the file now, and an index that points outside its own file ends the split with "[RED] /<file>: the game file is damaged: ...". PrepareText gives that line no Retry and the cause game_file_damaged, which the build shows as a damaged file. nximport_cli check reads plain NCAs whole against their hash layers too, so a dump can be checked without importing it. Tests: verify_test (new, 18 checks): plain and LZ4 dumps with and without the base's own package import, reading every file checks every block of the patched RomFS and the ExeFS, and a file cut short, a container entry shorter than its NCA, and bytes flipped in the base, in the update's RomFS header and in a file it carries, in its main, in a hash level, in an fs header, in an LZ4 base and in an add-on are each refused with the file and its role. The fixture's NCAs carry real hash layers and fs header hashes now. nsp_test (129), ncz_test (58), xci_test (9) and nup_meta_test (28) pass as before, also under ASan/UBSan and TSan on x86-64 Linux. test_damaged_game_files.py (14) and PrepareTextJvmTest cover the split and the card's words.
…igawa6#561) Measured on an AYN Thor with nximport_cli under the test app: Pokémon Legends: Z-A, its base, update 2.0.2 and a DLC into a 6.03 GB .nup took 11.6 and 12.7 s with the check and 10.9 and 11.7 s without it (main 4ae5c26), each run after sync and a pause. Both .nups were the same byte for byte. Peak memory went from 261 to 281 MiB, for the last hash level kept in memory. nximport_cli check read the three files whole in 15 s, all good. A copy of the 2.0.2 update with one byte changed in its middle: main wrote a .nup from it in 15.3 s; this branch stopped with "the update v393216 is damaged or incomplete: the bytes at 0x1627d8000 of its RomFS do not match their checksum" and wrote no .nup. The importer's tests (verify_test, nsp_test, ncz_test, xci_test, nup_meta_test, crypto, lz4, font) pass on the Thor with the same counts as main. HOOKS.md has the numbers, the FAQ the second, PEANUTS.md the status.
3 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the Peanuts side of #561.
What players get
.nupis damaged, the split now says so ("Finding the shaders stopped. A game file is damaged: arc › data.trpfs. Copy or dump the game again, then import it again.") with no Retry, instead ofstruct.error: unpack_from requires a buffer of at least 8725344222 bytes.Until now a damaged update became a
.nupwith a garbled file, and the build stopped half an hour later with a raw Python error and a Retry that failed again and again (#561: Z-A 2.0.2'sdata.trpfshad its right size and a garbled index).How
dm/peanuts/import/nx_verify.c, new): every plain NCA is checked against its own hash layers while the.nupis written. The fs header against its SHA-256 in the NCA header, the RomFS's IVFC levels and the ExeFS's hash table from the master hash down when the NCA is opened, then each data block as the writer reads it (below the decompression, every block once, on the writer's threads). An update's RomFS is checked through the patched image, and the base bytes it reads against the base's own levels, so the message names the file that is really damaged. The NCA's size is compared with its CNMT record and its header, and a file that ends early is refused before anything else. NCZs keep their whole-file check.shader_split.py): the FlatBuffers readers of Trinity'sdata.trpfd/data.trpfscheck every offset against the file; an index that points outside it ends the split with[RED] /<file>: the game file is damaged: ….PrepareTextgives that no Retry (FIX_NONE) and the causegame_file_damaged.dev.peanuts.build.DamagedFileturns the importer's message into the card's words; both cases end asFILE_DAMAGED(the game's sheet, no Retry).nximport_cli checknow also reads plain NSP/XCI files whole against their hash layers, so a dump can be checked without importing it.Tests
verify_test(new, 18 checks): plain and LZ4 dumps with and without the base's own package import; reading every file checks every block of the patched RomFS and the ExeFS; a file cut short, a container entry shorter than its NCA, and a byte flipped in the base, the update's RomFS header, a file the update carries, its main, a hash level, an fs header, an LZ4 base and a DLC are each refused with the file and its role, and no.nupis written. A damaged byte in a base file the update replaced is never read, so that import goes through.nsp_test(129),ncz_test(58),xci_test(9),nup_meta_test(28),font_test,crypto_test,lz4_testpass as before, also under ASan/UBSan and TSan (x86-64 Linux).peanuts/tests/test_damaged_game_files.py(14): the Trinity readers on a syntheticdata.trpfd/data.trpfs(good files read as before; a root, a pack offset or a descriptor past the end, a garbled root as in Pokémon Legends: Z-A — Shader splitting fails in Peanuts Native 0.1.7 #561, a cut descriptor, a pack table outside the file), the card's words, and the wiring.PrepareTextJvmTest: the split's line gets no Retry and its cause.On an AYN Thor
2026-11-25, the test app's identity,
nximport_clibuilt for arm64 from this branch and frommain(4ae5c26).Pokémon Legends: Z-A, base (4.3 GB), update 2.0.2 (2.1 GB) and the Mega Dimension DLC, from internal storage into a 6.03 GB
.nup, each run aftersyncand a pause:mainAbout a second more for a 6 GB game. Both
.nups are the same byte for byte (SHA-25690c6679c…), so a good dump imports as before. The 20 MiB is the last hash level kept in memory (32 bytes per 16 KiB block). Without thesync, the write-back of the previous run's.nupmade both swing between 13 and 24 s.nximport_cli checkread the three files whole in 15 s: 3 plain NCAs, all good.A copy of 2.0.2 with one byte changed in its middle:
mainwrote a.nupfrom it without a word (15.3 s), the damage as in Pokémon Legends: Z-A — Shader splitting fails in Peanuts Native 0.1.7 #561. This branch stopped with:and wrote no
.nup.The importer's tests on the Thor:
verify_test18,nsp_test129,ncz_test54,xci_test9,nup_meta_test28,crypto_test,lz4_test,font_testpass, the same counts asmainon the Thor (ncz_testcounts 58 on x86-64 Linux, onmaintoo).Not run: the card in the app with a damaged file (its words are covered by the JVM tests), a game on a microSD card, and a desktop build of
nximport_clion Windows or macOS.