Commit 87ccbea
committed
fix(handlers): fix infinite loop in zstd handler.
Given an invalid or truncated zstd file,
unblob/handlers/compression/zstd.py, in calculate_chunk(), did not check
for EOF in the while loop.
After reaching EOF, it always "reads" a block of type 0 and of size 0.
This is a valid block type (i.e. no raised exception) but not an "end
block" type, which is the only other condition to exit the loop.
Therefore, it kept looping actively and never returned.
Since we're reading from an mmap'ed file, reading from the file after
reaching EOF does not trigger an exception. Fixed by checking if the
read value is not empty and yielding an InvalidInputFormat exception
otherwise.
An integration test case reproducing the infinite loop has been added to
zstd test cases (truncated.dos.zstd).1 parent 3733fb3 commit 87ccbea
File tree
3 files changed
+8
-3
lines changed- tests/integration/compression/zstd
- __input__
- __output__/truncated.dos.zstd_extract
- unblob/handlers/compression
3 files changed
+8
-3
lines changedLines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
0 commit comments