Commit 2316998
committed
v2.4.1: gzipDecode is now decompression-bomb safe
Symmetry fix. brotli-decode.ts has had a 1 MB MAX_DECOMPRESSED_SIZE
cap with a real on-chain-style fixture
(testdata/brotli-decompression-bomb.txt.br -> 1 GB unzipped) since
forever. The gzip path in inscription-parser.service.helper.ts had
a bare 'while (true) chunks.push(value)' loop and would happily
allocate gigabytes if a future inscription used gzip Content-Encoding
to ship a HAHAHA-style bomb.
Now:
- gzipDecode tracks running totalSize, throws
MAX_DECOMPRESSED_SIZE_MESSAGE the moment the streamed output
crosses the cap, cancels the reader so the underlying
DecompressionStream stops pulling, and returns the sentinel
bytes the same way brotliDecodeUint8Array does.
- writer.write() / writer.close() now .catch() the abort error
that follows reader.cancel() (was unhandled before).
- testdata/gzip-decompression-bomb.sh mirrors brotli-decompression-bomb.sh
line for line (s/brotli/gzip/), with a one-line note about gzip's
auto-removal of the source file.
- testdata/gzip-decompression-bomb.txt.gz committed (949 KB compressed,
decompresses to ~1 GB).
- inscription-parser.service.gzip.spec.ts no longer has the
/* it('should survive a decompression bomb') ... TODO! */ placeholder;
it now has a real assertion that returns MAX_DECOMPRESSED_SIZE_MESSAGE,
matching brotli's spec exactly.
861 tests pass in both jest configs (was 860).
Note: the on-chain inscription that motivated this is one of the
HAHAHA-bomb cats (in the first ~300 cat21 mints). The exact txid
is unknown -- the synthetic fixture is sufficient for regression.
\xf0\x9f\x98\xba1 parent 016be86 commit 2316998
5 files changed
Lines changed: 64 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
2 | 4 | | |
| 5 | + | |
3 | 6 | | |
4 | 7 | | |
5 | 8 | | |
| |||
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
22 | 27 | | |
23 | | - | |
24 | 28 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
224 | 232 | | |
225 | 233 | | |
226 | 234 | | |
| |||
232 | 240 | | |
233 | 241 | | |
234 | 242 | | |
235 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
236 | 246 | | |
237 | | - | |
238 | | - | |
| 247 | + | |
| 248 | + | |
239 | 249 | | |
240 | | - | |
| 250 | + | |
| 251 | + | |
241 | 252 | | |
242 | 253 | | |
243 | 254 | | |
| |||
249 | 260 | | |
250 | 261 | | |
251 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
252 | 269 | | |
253 | 270 | | |
254 | 271 | | |
| |||
261 | 278 | | |
262 | 279 | | |
263 | 280 | | |
264 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
265 | 285 | | |
266 | 286 | | |
267 | 287 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
Binary file not shown.
0 commit comments