Loading arbitrary bytes as a ZIP and reading an entry fully into memory, with no ratio or size cap, is the textbook decompression bomb waiting to happen.
What goes wrong
The decode path takes any bytes the caller sends, opens them as a ZIP, and reads the target entry completely into memory as text. Nothing limits the archive size, the compression ratio, the entry size, or how much you extract.
Compression ratios of a thousand to one are ordinary, and crafted archives reach far higher. A payload small enough to slip past a request size limit expands into something that will not fit in memory. You are not defending against a big upload. You are defending against a small one that lies about how big it really is.
The pattern
function readArchive(bytes) {
const zip = openZip(bytes)
const entry = zip.get(ENTRY_NAME)
return readAllText(entry) // expands with no cap
}function readArchive(bytes) {
if (bytes.length > MAX_ARCHIVE) throw new Error('archive too large')
const zip = openZip(bytes)
const entry = zip.get(ENTRY_NAME)
if (entry.declaredSize > MAX_ENTRY) throw new Error('entry too large')
return readCapped(entry, MAX_ENTRY) // stop reading at the limit
}Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.
Why it matters to you
Zip bombs are old, which is exactly why they still work. The code that opens archives is often years old and was written for trusted files. The moment it sits behind an endpoint that accepts uploads, every assumption about well-behaved input is gone. One request can take a worker out of rotation, and a handful can take the service down.
Enforce a limit on the compressed input and on the extracted output, and read entries through a counting stream that aborts when it crosses the line. Trusting the size the archive declares is trusting the attacker.
Check your own code
- Cap the compressed archive size before opening it.
- Enforce a maximum extracted size per entry with a counting stream.
- Reject archives whose declared expansion ratio is implausible.
- Run a known zip bomb sample through the path in CI.