From 4ef0e2bd4a1875dcb90a98f2e56de582d59e2a27 Mon Sep 17 00:00:00 2001 From: ICUMADETHIS Date: Sun, 22 Nov 2026 08:10:07 +0000 Subject: [PATCH 1/3] Skip stored padding in raw NCZBLOCK blocks --- tests/ncz_test.py | 32 ++++++++++++++++++++++++++++++++ tools/ncz.py | 4 +++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/tests/ncz_test.py b/tests/ncz_test.py index 106f1a0d..1c451b2e 100644 --- a/tests/ncz_test.py +++ b/tests/ncz_test.py @@ -88,6 +88,25 @@ class UnpackTest(unittest.TestCase): def expected(self): return pfs0([(self.name + '.nca', self.nca), ('a.tik', self.tik)]) + def padded_nsz(self, indices, truncate=False): + """Store selected blocks raw, followed by padding included in the stored length, not the NCA body.""" + def pad(data): + head = ncz.HEADER + 16 + 0x40 * len(SECTIONS) + exponent = data[head + 11] + count = struct.unpack_from(' Date: Sun, 22 Nov 2026 08:37:42 +0000 Subject: [PATCH 2/3] Bound compressed NCZ blocks by their declared output size --- tests/ncz_test.py | 29 +++++++++++++++++++++++++++++ tools/ncz.py | 8 +++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/ncz_test.py b/tests/ncz_test.py index 1c451b2e..21a67de6 100644 --- a/tests/ncz_test.py +++ b/tests/ncz_test.py @@ -66,6 +66,35 @@ def ncz_file(nca, body, blocks=False): return out + b''.join(stored) +class BlocksTest(unittest.TestCase): + def read(self, data, plain=1 << 14): + header = b'NCZBLOCK' + bytes([2, 1, 0, 14]) + struct.pack(' Date: Sun, 22 Nov 2026 16:11:48 +0300 Subject: [PATCH 3/3] A block that decompresses to the wrong size is a damaged file again, so the installer asks for a fresh copy The size check added in this pull request raised a plain ValueError, which the installer maps to check.unpack_failed. Before it, such a block ended in a hash or length mismatch and the player saw check.input_damaged. ncz.unpack_ncz now turns the new BlockSizeError into DamagedFile, like ZstdError and EOFError. Co-Authored-By: Claude Opus 5.5 --- tests/ncz_test.py | 17 +++++++++++++++++ tools/ncz.py | 11 +++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/ncz_test.py b/tests/ncz_test.py index 21a67de6..14554cc6 100644 --- a/tests/ncz_test.py +++ b/tests/ncz_test.py @@ -163,6 +163,23 @@ class UnpackTest(unittest.TestCase): ncz.unpack(self.padded_nsz((-1,), truncate=True), self.dir / 'out.nsp') self.assertFalse((self.dir / 'out.nsp').exists()) + def test_block_of_the_wrong_size_is_a_damaged_file(self): + """The installer turns DamagedFile into check.input_damaged, which asks for a fresh copy of the file.""" + def short(data): + head = ncz.HEADER + 16 + 0x40 * len(SECTIONS) + count = struct.unpack_from('