Commit 6c387f9
committed
Fix ZstdDecoder to propagate UnexpectedEof error on truncated streams
The Zstd decoder was silently accepting truncated streams by not
validating stream completion in finish().
This issue was discovered by the generic truncated stream test.
Added state tracking to ZstdDecoder:
- Added stream_ended field to track if remaining == 0 was seen
- Modified decode() to set stream_ended = true when stream completes
- Updated finish() to check stream_ended and return UnexpectedEof if false
- Updated all constructors to initialize stream_ended = false
This matches the behavior of other decoders (bzip2, gzip, lz4, etc.) and
ensures applications cannot accidentally accept corrupted or incomplete
zstd data as valid.
The generic truncated test now passes for Zstd.1 parent 40ad91c commit 6c387f9
1 file changed
+21
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
| |||
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
| 71 | + | |
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
| |||
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
83 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
84 | 94 | | |
85 | 95 | | |
86 | 96 | | |
87 | 97 | | |
88 | 98 | | |
89 | 99 | | |
90 | 100 | | |
91 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
92 | 111 | | |
93 | 112 | | |
94 | 113 | | |
| |||
0 commit comments