node-tar fails to enforce maxDecompressionRatio leading to DoS
The tar library evaluates its decompression ratio guard after the data has already been inflated, allowing an attacker to trigger out‑of‑memory conditions with a single crafted archive. This bypass defeats the intended protection and can bring services using node‑tar to a halt.
Node‑tar’s maxDecompressionRatio check runs on the 'data' event after zlib has produced the full output chunk, so the guard sees the already‑expanded size instead of limiting it.
- The check is performed on each
write()call; a large write can allocate up toinputSize × 1000bytes before the ratio is evaluated. - Compression codecs such as zstd (≈32,700:1) and brotli (≈1,230,000:1) can exceed the 1000‑ratio limit in a single chunk, bypassing the guard entirely.
- The library writes up to 16 MB per file‑reading helper, further amplifying the memory spike.
- No
maxOutputLengthis set on the underlying decompressors, leaving the allocation unchecked.
Engineering Takeaway: Validate decompression limits on the raw input stream or enforce a hard output cap to prevent unbounded memory use.





