# GHSA-5QXQ-CGM8-6J7R: node-tar async extract: deep symlink linkpath reaches quadratic getDirs, causing uncatchable heap-exhaustion DoS

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

## Tracked as

- [CVE-2026-140119](https://cve.now/CVE-2026-140119.md): node-tar denial of service in async archive extraction

## Affected versions

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

## Description

## Summary

node-tar's default asynchronous extractor (`tar.extract({file})` and the `Unpack` stream) serializes overlapping filesystem operations through a `PathReservations` system. For a symbolic-link or hardlink entry, the filesystem check reserves both the entry path and its link target (`entry.linkpath`), and `reserve()` expands every reserved path into its full chain of ancestor directories via the `getDirs` helper in `src/path-reservations.ts`. `getDirs` rebuilds a growing path prefix with `join()` once per path segment, so it costs O(N^2) time and retains O(N^2) memory in the number of segments. The depth limit that bounds how deep an entry may be (added when the folders-depth denial-of-service issue was remediated) is applied only to `entry.path`; `entry.linkpath` is passed through the absolute-path stripper, which only rejects `..`. An unauthenticated attacker who supplies a crafted archive whose single member is a symlink with a very deep `linkpath` of the form `a/a/a/...` reaches `getDirs` with no depth bound. Because the quadratic blowup runs synchronously inside the parser write path and exhausts the heap, it aborts the Node.js process with an uncatchable fatal out-of-memory error. A 26 KB archive is sufficient on a default (about 2 GB) heap.

## Root Cause

The extractor enforces a depth invariant (`maxDepth`, default 1024) to prevent path-component-depth resource exhaustion, but it enforces that invariant on only one of the two attacker-controlled path fields. The check in `Unpack` measures the segment count of `entry.path`; `entry.linkpath` never has its depth measured. The absolute-path stripper applied to `linkpath` rejects only `..` sequences and cwd escapes, so a deep but relative `linkpath` survives validation intact and flows into the path-reservation machinery, where the `getDirs` helper is quadratic in the segment count. The same quadratic sink is reachable through `entry.path` as well, but that field is bounded by the depth check, so in practice the unbounded `linkpath` is the exploitable route.

```text
Affected components (repository-relative):
- src/path-reservations.ts, getDirs (line 25): split('/').slice(0,-1).reduce with join(prev, seg) rebuilds a growing prefix per segment -> O(N^2) time and O(N^2) retained memory.
- src/path-reservations.ts, PathReservations.reserve (line 52): maps every reserved path (including the deep entry.linkpath) through getDirs with no depth bound.
- src/unpack.ts, Unpack CHECKPATH (line 320): applies the maxDepth guard at line 342 to entry.path segments only; entry.linkpath depth is never bounded (STRIPABSOLUTEPATH at line 254 checks only '..'/cwd-escape).
- src/unpack.ts, Unpack CHECKFS (lines 730-734): pushes entry.linkpath into reserve() for SymbolicLink/Link entries.
```

## Impact

An unauthenticated remote attacker who can cause a service to extract an attacker-supplied tar archive with the default asynchronous API on a POSIX host can terminate the extracting Node.js process. The demonstrated capability is a hard, process-fatal out-of-memory abort (exit code 134) that a surrounding `try/catch` around `await tar.extract(...)` cannot intercept, because a V8 heap-exhaustion abort is not a catchable JavaScript exception. The attack requires no authentication, no privileges, and no user interaction, and is deterministic. It is a pure availability impact with no confidentiality or integrity consequence. The amplification is high and the cost is low: a 26 KB archive kills the process, and a roughly 400 KB `linkpath` (about 200000 segments, well under the 1 MiB metadata-entry size limit) scales the attack to much larger heaps.

## Proof of Concept

```text
Environment: npm tar 7.5.22, Node.js v24.21.0 (default ~2.2 GB heap), POSIX (Linux x64), default options.
```

Reproduction steps:

1. Build a tar whose single member is a symlink carrying a deep PAX `linkpath` extended record of the form `a/a/.../a` (12000 segments produces a 26 KB archive).
2. Extract it with the default asynchronous API and wrap the call in a `try/catch`.
3. Observe the process abort with a fatal out-of-memory error and exit code 134; no catch handler runs.

```javascript
// victim.mjs - default async extractor, wrapped in try/catch
import tar from 'tar'
try {
  await tar.extract({ file: 'evil.tar', cwd: destDir })   // default async Unpack path
  console.log('extract returned normally')
} catch (e) {
  console.log('caught:', e && e.message)   // never reached: OOM is uncatchable
}
```

```text
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
(process aborts, exit 134; no "caught:" line printed)

Standalone getDirs complexity (verbatim copy of the helper):
  N=1000  ms=69.63   totalChars=998001
  N=2000  ms=262.47  totalChars=3996001
  N=4000  ms=1069.31 totalChars=15992001
  -> time x4 per x2 of N, retained chars ~= N^2 (clean O(N^2)); standalone OOM near N=8000.

Negative control (deep entry.path instead of linkpath): async extract emits
  WARN TAR_ENTRY_ERROR path excessively deep
and returns normally (exit 0), confirming the depth guard is active on path only.
Negative control (sync:true): returns normally (exit 0); the synchronous extractor does not use path reservations.
```

## Attack Chain

1. **Exposure:** A service extracts an untrusted archive with the default asynchronous `tar.extract`/`Unpack` API on a POSIX host, which is node-tar's core threat model.
2. **Control:** The attacker sets a symlink entry's `linkpath` to a deep relative path `a/a/.../a` via a PAX extended record. The metadata-entry size limit is 1 MiB, and 12000 segments is about 26 KB, so the record is ingested.
3. **Path:** The entry passes `Unpack` path checking; the depth guard measures `entry.path` (a short name here) and never `entry.linkpath`. The absolute-path stripper is applied to `linkpath` but only rejects `..`/cwd escapes, so the deep relative value passes unchanged.
4. **Guard:** The depth invariant is enforced on `entry.path` only. There is no depth bound on `entry.linkpath`, and no guard exists between the filesystem check and the quadratic helper.
5. **Primitive:** For the symlink entry, the filesystem check pushes `entry.linkpath` into `reserve()`, which maps it through `getDirs`; `getDirs` runs a quadratic prefix rebuild synchronously inside the parser write path.
6. **Result:** The O(N^2) time and retained memory exhaust the V8 heap and abort the process with an uncatchable fatal out-of-memory error (exit 134), denying service to the extracting process.

## Bypass Evidence

The relevant prior fix is the folders-depth denial-of-service remediation (CVE-2024-28863, GHSA-f5x3-32g6-xq36), which introduced the `maxDepth` guard in the path-checking routine. That guard is present in the released 7.5.22 artifact but is incomplete: it measures the segment count of `entry.path` only, while the identical quadratic sink (`getDirs`) is also reachable through `entry.linkpath`, which is never depth-bounded. The absolute-path stripper applied to `linkpath` rejects only `..` and cwd escapes, so a deep relative `linkpath` bypasses every validation between ingestion and the sink.

Attempts to disprove the finding, and their outcomes:

- Hypothesis that the strip block also bounds `linkpath` depth: refuted. That block runs only when `strip` is set (default 0) and merely slices segments; it never bounds depth.
- Hypothesis that path normalization collapses the deep `a/a/.../a` value: refuted. With no `..`, nothing collapses, and the stripper returns the deep value intact.
- Hypothesis that `getDirs` is linear or merely slow: refuted by measurement (time quadruples per doubling of segment count) and by an end-to-end fatal out-of-memory abort from a 26 KB archive.
- Hypothesis that the out-of-memory error is catchable: refuted. The `try/catch` around `await tar.extract` never runs its handler; the process aborts with exit 134.
- Hypothesis that this duplicates the folders-depth issue, the member-selection recursion issue (CVE-2026-73566), or the decompression issue (CVE-2026-59873): refuted. The file, function, mechanism, and sink differ, and no published advisory covers the `linkpath`-to-`getDirs` quadratic-heap vector.

This vector is out of scope on Windows (path reservations are short-circuited to a constant list) and on the synchronous extractor (which does not use reservations); both were reproduced returning normally.

## Affected Versions

- `Ecosystem: npm`
- `Package: tar`
- `Confirmed affected range: <= 7.5.22`
- `Latest release checked: 7.5.22 (npm dist-tags.latest; git tag v7.5.22)`
- `Fix status: not fixed`

The vulnerable path (`entry.linkpath` reaching `reserve()` and `getDirs`) lives in the `PathReservations`-based asynchronous extractor introduced in the node-tar v6 rewrite and was never depth-bounded; the depth guard that this bypasses was added later and applied only to `entry.path`. The exact first-affected release was not bisected, so the introduced boundary is left open rather than asserted. No released or unreleased fix exists, so the latest published release 7.5.22 is affected and the upper bound is `<= 7.5.22`.

## Suggested Fix

Enforce the same depth invariant on `entry.linkpath` that is already enforced on `entry.path` (reject or reduce a link target whose segment count exceeds `maxDepth`), and/or make `getDirs` linear so that expanding a path into its ancestor directories no longer costs O(N^2) time or memory (for example, accumulate ancestor prefixes with a single running index instead of re-joining the growing prefix each iteration). The remediation must cover every reserved path field, not only `entry.path`, and must apply to symbolic-link and hardlink entries whose `linkpath` is pushed into the reservation system. As an interim mitigation, extracting untrusted archives with the synchronous API (`sync: true`) avoids the path-reservation code path, and lowering `maxDepth` does not help because it does not apply to `linkpath`; there is no configuration option that bounds link-target depth today.

---

Reported by zx (GitHub: @manus-pi).

## References

- https://github.com/isaacs/node-tar/security/advisories/GHSA-5qxq-cgm8-6j7r

Page: https://cve.now/GHSA-5QXQ-CGM8-6J7R

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