GitHub advisory · npm
node-tar PathReservations.getDirs() quadratic memory amplification via unbounded symlink linkpath depth — uncatchable OOM process kill
Description
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.
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
THE UNCATCHABLE FAILURE MODE
The OOM occurs during PathReservations…
Manual fix · npm
npm install tar@8.0.0Sources