Decode attacker input, then inflate it with no ceiling on the output, and anyone with a network connection has a one-line way to exhaust your memory.
What goes wrong
A few kilobytes can turn into a few gigabytes, and this function allocates every one of them without blinking. The decode path takes a caller's string, turns it back into bytes, then runs those bytes through decompression. Nowhere does it ask how large the result is allowed to get.
Because the function is exported and reachable from the network with no auth, the whole cost lands on the defender. On a single-threaded runtime the inflate call also blocks the event loop, so one request can stall every other request in flight. You do not need a botnet. One client and a loop will do.
The pattern
function decode(input) {
const raw = fromTextEncoding(input) // untrusted, off the wire
const bytes = inflate(raw) // no cap on output size
return parse(bytes) // whatever came out
}
// 3 KB in can become 900 MB outfunction decode(input) {
const raw = fromTextEncoding(input)
if (raw.length > MAX_COMPRESSED) throw new Error("input too large")
// inflate incrementally, abort past the ceiling
const bytes = inflateWithLimit(raw, MAX_DECOMPRESSED)
return parse(bytes)
}Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.
Why it matters to you
Availability bugs get filed under "later" until the day one goes off in production. A decompression bomb is cheap to send and hard to tell apart from a legitimate large payload after the fact. If this decoder sits on a hot path, a single client can degrade or drop service for everyone.
The fix is boring, and that is the point. Put a ceiling on the compressed input and a separate ceiling on the decompressed output, then decompress in chunks so you can bail the moment either is crossed.
Check your own code
- Find every decompress or inflate call and confirm each has a hard output-size limit.
- Reject oversized inputs before you allocate anything based on their content.
- On single-threaded runtimes, move heavy decode work off the request thread.
- Load-test the decoder with a maximally compressible payload, not a typical one.