Skip to main content
Menu
Advisories

Uncapped linkpath drives quadratic getDirs in async path reservation causing uncatchable OOM DoS

GHSA-343G-5V7X-X325Published Updated GitHub

Description

tar's asynchronous extract path (tar.x, tar.extract, new Unpack()) runs an uncapped, quadratic PathReservations.getDirs() over entry.linkpath. An attacker who supplies a tar archive with a deeply-nested link target (delivered via a GNU 'K' long-linkpath meta entry, bounded only by maxMetaEntrySize = 1 MB) causes O(n^2) CPU work and unbounded transient memory on the main thread, freezing the event loop and then triggering an uncatchable FATAL ERROR: heap out of memory that kills the whole Node process. A ~42 KB archive reliably crashes a default-heap Node process (verified: exit code 134 / SIGABRT; neither try/catch nor process.on('uncaughtException') intercepts).

Root Cause

The CVE-2024-28863 fix (GHSA-f5x3-32g6-xq36) added a maxDepth (default 1024) component-count cap in Unpack[CHECKPATH] (src/unpack.ts:342), but the cap is computed from entry.path ONLY — parts = normalizeWindowsPath(entry.path).split('/') (src/unpack.ts:321-322). entry.linkpath never enters that computation; its only sanitizer is [STRIPABSOLUTEPATH] (src/unpack.ts:254-317), which rejects parts.includes('..') but imposes no depth or length bound.

In the default async unpack path, [ONENTRY] routes both Link and SymbolicLink entries to [CHECKFS], which pushes BOTH entry.path and entry.linkpath into reservations.reserve() (src/unpack.ts:730-734). PathReservations.reserve() calls paths.map(getDirs) (src/path-reservations.ts:62). getDirs() (src/path-reservations.ts:25-38) builds ancestor directories by repeatedly join()-ing an accumulating prefix and retaining every intermediate string, so for an n-component path it does O(n^2) character-work and holds O(n^2) transient string bytes.

An attacker delivers an arbitrarily deep linkpath via a standard GNU 'K' long-linkpath meta entry (or PAX linkpath=), bounded only by maxMetaEntrySize (1 MB, src/parse.ts:29, enforced at src/parse.ts:241). A ~900 KB linkpath of single-char components (~450,000 components) drives ~10^11 char-ops and >100 GB of transient allocation. Uncompressed archives keep the decompression ratio far below the 1000 default, so the CVE-2026-59873 maxDecompressionRatio guard never fires.

Impact

Remote unauthenticated denial of service (CWE-407 algorithmic complexity + CWE-400 uncontrolled resource consumption). The O(n^2) work runs synchronously on the main thread inside the 'entry' handler (full event-loop freeze), then triggers an uncatchable process crash. Amplification is high (~42 KB input crashes default Node) and the crash cannot be caught by application-level handlers, so this is not a run-of-the-mill "slow request" DoS. Affects any service that extracts untrusted tar archives on the default async path: CI artifact/cache restore, package installers, upload/import processors. POSIX-only (reserve() is a no-op on Windows, src/path-reservations.ts:53-55).

Proof of Concept

Craft an uncompressed tar with a GNU 'K' (NextFileHasLongLinkpath) meta entry whose ~900 KB body is a/a/a/... (~450,000 single-char components), immediately followed by a hardlink entry (typeflag 1) named victim. The victim runs the default async extract:

import { x } from 'tar'
await x({ file: 'bomb.tar', cwd: './out' })
// event-loop freezes for seconds, then: FATAL ERROR: Ineffective mark-compacts
// near heap limit — process exits 134 (SIGABRT). try/catch and
// process.on('uncaughtException') do NOT intercept.

Empirically reproduced on tar built from HEAD (v7.5.22), Node v24.18.0: N=8000 (18 KB archive) froze extract 8.1s with RSS ~2.0 GB; N=20000 (42 KB archive) with --max-old-space-size=512 crashed with exit 134 and neither handler fired.

Attack Chain

  1. Entry: untrusted .tar with a GNU 'K' meta entry (<=1 MB body = a/a/..., ~450k comps) followed by a hardlink entry victim.
  • Guard: maxMetaEntrySize = 1 MB (src/parse.ts:29, enforced src/parse.ts:241 before meta accumulation).
  • Bypass proof: 900 KB < 1 MB → accepted; EMITMETA (src/parse.ts:394-398) sets ex.linkpath; slurp (src/read-entry.ts:135-149) overrides the short header linkname onto the following Link entry.
  1. Trigger: victim runs default tar.x({ file, cwd }).
  • Guard: [CHECKPATH] maxDepth = 1024 (src/unpack.ts:342).
  • Bypass proof: cap uses entry.path only (src/unpack.ts:321-322); entry.path = "victim" (1 component) passes. Verified on a 5000-comp test: parsed entry is {type:"Link", path:"victim", linkpathLen:9999, comps:5000} — the deep linkpath arrives intact at [CHECKFS].
  1. Sink: [ONENTRY](Link) → [CHECKFS] reserves [path, linkpath] (src/unpack.ts:730-734) → reserve() → getDirs(linkpath) (src/path-reservations.ts:62,25-38).
  • Guard: none on linkpath.
  • Bypass proof: O(n^2) over ~450k components → event-loop freeze then uncatchable heap-OOM (exit 134, empirically verified).
  1. Defense-in-depth: maxDecompressionRatio = 1000.
  • Bypass proof: archive is uncompressed (ratio ~1); the guard measures bytes, not per-field component count, so it never trips.

Bypass Evidence

  • grep -rn maxDepth src/ → cap computed from entry.path alone (src/unpack.ts:321-322,342); no parser/header-level segment cap exists (grep of parse.ts/header.ts/read-entry.ts/pax.ts for segment length → none).
  • [STRIPABSOLUTEPATH] (src/unpack.ts:254-317) rejects only ..; an a/a/a/... payload has no .. → passes untouched, no length bound.
  • Isolated verbatim-getDirs benchmark: time and peak memory scale ~4x per doubling of n = clean O(n^2); OOM at n=16000 on a 3 GB heap.
  • Real tar.x reproduction: N=8000 → 8.1s main-thread freeze, ~2.0 GB RSS; N=20000 (--max-old-space-size=512) → exit 134 (SIGABRT), neither try/catch nor uncaughtException fired.

Affected Versions

<= 7.5.22 (current npm latest). The uncapped-linkpath gap and the async reserve() → getDirs() path are present on HEAD (2a22bfc = v7.5.22) with no unreleased fix. Distinct in file, function, mechanism, field, precondition, and fix from every existing node-tar advisory (see below).

Distinctness (not a duplicate)

  • GHSA-f5x3-32g6-xq36 / CVE-2024-28863 (maxDepth fix): the fix caps entry.path depth only; this finding is the linkpath vector the fix never covered → incomplete-fix / distinct vector.
  • GHSA-r292-9mhp-454m (mapHas/filesFilter recursion): same class but different file (path-reservations.ts vs list.ts), function (getDirs vs mapHas), CWE/mechanism (CWE-407 quadratic → heap OOM vs CWE-674 recursion → stack RangeError), driving field (linkpath vs path), precondition (fires on ANY hardlink/symlink in default tar.x with NO member-selection list, vs requires a member-selection list), and fix.
  • GHSA-23hp-3jrh-7fpw / CVE-2026-59873 (decompression-ratio DoS): bounds byte ratio only; PoC archive is uncompressed. Different sink.

Suggested Fix

Apply a component-count/length bound to entry.linkpath in [CHECKPATH] mirroring the existing entry.path maxDepth check, and/or rewrite getDirs to O(n) (accumulate with a running prefix instead of retaining every intermediate string).

--- Reported by zx (Jace) — GitHub: @manus-use

Affected versions

References

GitHub · isaacs/node-tar