Merge branch 'pr1351-head' into task/pr1351

This commit is contained in:
Valiantsin Dzerakh committed 2026-11-22 16:04:59 +03:00
commit 516b1d2ab5
2 files changed
+71 -2

No files matched your search

+10 -2
View File
@@ -126,9 +126,17 @@ def blocks(f, pos, end, total):
for i, length in enumerate(stored):
plain = min(1 << exponent, size - (i << exponent))
require(pos + length <= end, 'Truncated NCZ block')
data = read_at(f, pos, length)
# nsz's BlockDecompressorReader.py __decompressBlock skips padding in a raw block: only plain bytes belong
# to the NCA, while the full stored length locates the next block.
data = read_at(f, pos, min(length, plain))
pos += length
yield zstd.decompress(data) if length < plain else data
if length < plain:
# Read at most one byte beyond the declared size: a damaged frame must not allocate its whole output.
# ZstdFile also preserves support for concatenated frames within a block.
with zstd.ZstdFile(io.BytesIO(data)) as z:
data = z.read(plain + 1)
require(len(data) == plain, 'NCZ block decompressed size does not match its header')
yield data
def stream(f, pos, end, total):