node-tar crashes the process with an uncaught exception on a 4-byte zstd magic header when the Node runtime lacks native zstd
Published 2 Dec 2026 · Updated 2 Dec 2026
Affected package
- Affected
- >=7.5.22 <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
An unauthenticated remote-input denial of service allows a four-byte file to crash any process that lists or extracts it with node-tar's asynchronous file API, on any Node runtime without native zlib zstd support (Node 18.x, 20.x, 21.x, 22.0-22.14, 23.0-23.7, all of which satisfy the package's declared engines: node >= 18). node-tar's default-enabled compression sniffing detects the zstd magic (28 b5 2f fd) and constructs new ZstdDecompress({}) with no error handling. On a runtime without the zstd binding, minizlib's constructor throws a TypeError synchronously inside the file-read stream's data callback, so the async tar.t() / tar.x() promise never settles and the exception is uncaught, killing the process.
Details
Parser.write() sniffs the first bytes of every input and, on the zstd magic, constructs the decompressor unguarded:
// src/parse.ts:547-550
this[UNZIP] =
this[UNZIP] === undefined ? new Unzip({})
: isZstd ? new ZstdDecompress({}) // throws TypeError on a runtime without native zstd
: new BrotliDecompress({})minizlib's ZlibBase constructor throws TypeError: Compression method not supported: ZstdDecompress when node:zlib lacks the binding. Because this construction runs inside the file-read stream's data handler (ReadStream.emit -> Unpack.write -> new ZstdDecompress), the throw is not routed through the stream's error event or Parser.abort(). For the async file form (tar.x({file}) / tar.t({file})), the throw escapes as an uncaught exception: the process dies, and a consumer's try/catch or .catch() cannot reach it because the returned promise never settles. zlib.ZstdDecompress was added in Node v23.8.0 and backported to v22.15.0; on those and later runtimes the class exists and the same 4-byte input is handled through the normal catchable error path instead.
PoC
Validated on the published npm package tar@7.5.22 (and source main @ 2a22bfc). Vulnerable runtime: Node v20.20.2 (node -e "console.log(typeof require('zlib').ZstdDecompress)" prints undefined). Non-vulnerable control: Node v24.19.0.
// npm i tar@7.5.22 ; node poc.cjs (run on Node 20)
const { x } = require('tar'); const fs = require('fs')
fs.writeFileSync('/tmp/z4.tar', Buffer.from([0x28,0xb5,0x2f,0xfd,0x01,0x02,0x03,0x04]))
fs.rmSync('/tmp/z-out',{recursive:true,force:true}); fs.mkdirSync('/tmp/z-out')
let uncaught = null, settled = 'NEVER'
process.on('uncaughtException', e => uncaught = e.constructor.name + ': ' + e.message)
x({ cwd:'/tmp/z-out', file:'/tmp/z4.tar' }).then(()=>settled='RESOLVED').catch(()=>settled='REJECTED')
const ka = setInterval(()=>{},100)
setTimeout(()=>{ clearInterval(ka); console.log('uncaught:', uncaught); console.log('settled:', settled); process.exit(0) }, 3000)Observed on Node v20.20.2 (zstd undefined):
uncaught: TypeError: Compression method not supported: ZstdDecompress settled: NEVER
Without the uncaughtException handler the process dies with the raw stack (frame: at new ZstdDecompress ... at Unpack.write ... at FSReqCallback.wrapper [as oncomplete] (node:fs)). On Node v24.19.0 the same file produces a clean catchable rejection (TAR_ABORT / zlib: Dictionary mismatch) and no crash. Synchronous mode and direct stream writes throw catchably from the caller's stack on all runtimes; only the async file API turns the throw into process death.
Impact
Availability-only denial of service via process crash. Four attacker-controlled bytes, with no tar structure, kill any pipeline on an affected Node runtime that lists or extracts an attacker-supplied archive through node-tar's async file API, including npm-style package installation and CI artifact processing. The impact is conditional on the Node version: it is present on Node 18.x, 20.x, 21.x, 22.0-22.14, and 23.0-23.7 (Node 20 is an Active LTS line in wide production use) and inert on Node 22.15+ / 23.8+ / 24+. Unauthenticated, remote, no user interaction.
Is GHSA-72fp-85cc-g945 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-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
- HighCVE-2026-140238node-tar: Newline injection in PAX extended-header records enables entry-attribute forgery (path overwrite → npm postinstall RCE on Windows) · 2 Dec 2026
- HighCVE-2026-140239node-tar: Global PAX extended header injects attacker-controlled linkpath into tar.Parser entries, bypassing strict-mode validation · 2 Dec 2026
References
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.