Commit 10a7776
fix(security): protect against zip-bomb attacks via inflated row_count
Two independent OOM vectors, both exploitable with files under 200 bytes
claiming 10⁹ rows:
1. ConstantEncoding.Decoder stored n copies of the constant value.
A ~130-byte file triggers an 8 GB allocation in decode() before
touching any actual data.
Fix: store one element only; array reports length=n with O(1) buffer.
Callers that need all n values replicate from index 0.
2. ScanIterator.expandDictPrimitive pre-allocated n × elemBytes from
the attacker-controlled codesLayout.rowCount() before reading a
single code byte. PrimitiveEncoding wraps the mmap'd segment without
allocating, making the rowCount inflation invisible at decode time.
Fix: validate bufferCodes >= n in decodeDictLayout before expansion;
the mmap-bounded buffer makes inflation detectable for direct-mapped
encodings, and full-decode encodings (bitpacked etc.) already fill
their buffer to n × elemBytes during decode.
Regression tests in ZipBombTest use row counts safe for CI: 10M for
attack 1 (fails with AssertionError if reverted, not OOM) and 100 for
attack 2 (wrong exception type → clean failure if check is removed).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 5c17761 commit 10a7776
4 files changed
Lines changed: 408 additions & 18 deletions
File tree
- core/src
- main/java/io/github/dfa1/vortex/encoding
- test/java/io/github/dfa1/vortex/encoding
- reader/src
- main/java/io/github/dfa1/vortex/scan
- test/java/io/github/dfa1/vortex/io
Lines changed: 11 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
| 126 | + | |
128 | 127 | | |
129 | 128 | | |
130 | 129 | | |
| |||
163 | 162 | | |
164 | 163 | | |
165 | 164 | | |
166 | | - | |
| 165 | + | |
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
| |||
176 | 175 | | |
177 | 176 | | |
178 | 177 | | |
179 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
180 | 183 | | |
181 | | - | |
182 | | - | |
183 | | - | |
| 184 | + | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
| |||
220 | 221 | | |
221 | 222 | | |
222 | 223 | | |
223 | | - | |
224 | | - | |
| 224 | + | |
| 225 | + | |
225 | 226 | | |
226 | 227 | | |
227 | 228 | | |
| |||
248 | 249 | | |
249 | 250 | | |
250 | 251 | | |
251 | | - | |
| 252 | + | |
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
| |||
Lines changed: 35 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
16 | 45 | | |
17 | 46 | | |
18 | 47 | | |
| |||
48 | 77 | | |
49 | 78 | | |
50 | 79 | | |
51 | | - | |
| 80 | + | |
52 | 81 | | |
53 | | - | |
54 | | - | |
55 | | - | |
| 82 | + | |
| 83 | + | |
56 | 84 | | |
57 | 85 | | |
58 | 86 | | |
| |||
68 | 96 | | |
69 | 97 | | |
70 | 98 | | |
71 | | - | |
| 99 | + | |
72 | 100 | | |
73 | | - | |
74 | | - | |
75 | | - | |
| 101 | + | |
| 102 | + | |
76 | 103 | | |
77 | 104 | | |
78 | 105 | | |
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
432 | 443 | | |
433 | 444 | | |
434 | 445 | | |
| |||
0 commit comments