Commit e6b3819
fix:
* Add generic truncated stream test to all decoders
Added a generic truncated stream test to the test_cases! macro that
automatically tests all decoders (bzip2, gzip, deflate, zlib, xz, lzma,
lz4, zstd, brotli) for proper handling of incomplete streams.
The test compresses data, truncates it, then attempts decompression.
Decoders should return UnexpectedEof errors for truncated streams
instead of silently accepting incomplete data.
This test currently fails for bzip2, lz4, and zstd decoders, which
will be fixed in subsequent commits.
* Fix BzDecoder to propagate UnexpectedEof error on truncated streams
Fixes #411
The async BzDecoder was silently accepting truncated bzip2 streams,
returning Ok(0) instead of raising an error. This contrasts with the
synchronous bzip2::read::BzDecoder which properly returns an
UnexpectedEof error.
Added state tracking to BzDecoder:
- Added stream_ended field to track if Status::StreamEnd was received
- Modified decode() to set stream_ended = true on Status::StreamEnd
- Updated finish() to check stream_ended and return UnexpectedEof if false
This ensures applications cannot accidentally accept corrupted or
incomplete compressed data as valid, matching the behavior of the
synchronous decoder.
The generic truncated test now passes for bzip2.
* Fix Lz4Decoder to propagate UnexpectedEof error on truncated streams
The LZ4 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 Lz4Decoder:
- 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
This matches the behavior of other decoders (bzip2, gzip, etc.) and
ensures applications cannot accidentally accept corrupted or incomplete
LZ4 data as valid.
The generic truncated test now passes for LZ4.
* 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.
---------
Co-authored-by: Claude <[email protected]>UnexpectedEof on truncated input (#412)1 parent 83a06fe commit e6b3819
File tree
4 files changed
+79
-5
lines changed- crates
- async-compression/tests/utils
- compression-codecs/src
- bzip2
- lz4
- zstd
4 files changed
+79
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
234 | 254 | | |
235 | 255 | | |
236 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
52 | 59 | | |
53 | 60 | | |
54 | 61 | | |
55 | 62 | | |
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
| 66 | + | |
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
| |||
101 | 109 | | |
102 | 110 | | |
103 | 111 | | |
104 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
105 | 120 | | |
106 | 121 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
77 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
| |||
92 | 100 | | |
93 | 101 | | |
94 | 102 | | |
95 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
96 | 113 | | |
97 | 114 | | |
| 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 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
87 | 100 | | |
88 | 101 | | |
89 | 102 | | |
90 | 103 | | |
91 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
92 | 114 | | |
93 | 115 | | |
94 | 116 | | |
| |||
0 commit comments