mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-22 21:15:57 +00:00
Bound compressed NCZ blocks by their declared output size
This commit is contained in:
1 parent
4ef0e2bd4a
commit
8bbc6c7ade
2 files changed
+36
-1
No files matched your search
+7
-1
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user