Bound compressed NCZ blocks by their declared output size

This commit is contained in:
ICUMADETHIS committed 2026-11-22 08:37:42 +00:00
1 parent 4ef0e2bd4a
commit 8bbc6c7ade
2 files changed
+36 -1

No files matched your search

+7 -1
View File
@@ -130,7 +130,13 @@ def blocks(f, pos, end, total):
# 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):