Skip to content

Commit 1facc7d

Browse files
authored
Merge pull request #635 from onekey-sec/634-fix-zstd-infinite-loop
fix(handlers): fix infinite loop in zstd handler.
2 parents 3733fb3 + 87ccbea commit 1facc7d

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:052ba0688dc57289ad3bb5863ac952b4ff8d91156e3a3a274e60ef2ad1746015
3+
size 9

tests/integration/compression/zstd/__output__/truncated.dos.zstd_extract/.gitkeep

Whitespace-only changes.

unblob/handlers/compression/zstd.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ def calculate_chunk(self, file: File, start_offset: int) -> Optional[ValidChunk]
5858

5959
last_block = False
6060
while not last_block:
61-
block_header = int.from_bytes(
62-
file.read(BLOCK_HEADER_LEN), byteorder="little"
63-
)
61+
block_header_val = file.read(BLOCK_HEADER_LEN)
62+
# EOF
63+
if not block_header_val:
64+
raise InvalidInputFormat("Premature end of ZSTD stream.")
65+
block_header = int.from_bytes(block_header_val, byteorder="little")
6466
last_block = block_header >> 0 & 0b1
6567
block_type = block_header >> 1 & 0b11
6668

0 commit comments

Comments
 (0)