GHSA-PH3C-P786-J4RP

Vulnerability from github – Published: 2026-12-02 01:14 – Updated: 2026-12-02 01:14
VLAI
Summary
node-tar: Non-finite PAX size (Infinity) bypasses validation, causing extraction entry loss and an uncaught exception when re-packing
Details

Summary

tar (node-tar) does not validate that a numeric size value supplied through a PAX extended header (typeflag x) is finite before it is applied to the following archive entry. A PAX record such as 17 size=Infinity\n is coerced to the JavaScript number Infinity and accepted, because the only guard on the value is a >= 0 check and Infinity >= 0 is true. The non-finite size then propagates into the entry-body state machine and, when the entry is re-packed, into numeric header encoding. Any process that parses, extracts, lists, or re-packs an attacker-supplied archive is affected; no authentication or non-default configuration is required.

Root Cause

The PAX key/value parser assigns the size field after a check that was designed only to reject negative values. It never checks that the coerced number is finite or a safe integer, so Infinity (and other non-finite positive values) pass.

// src/pax.ts (parseKVLine)
case 'size':
  const s = +v            // +"Infinity" === Infinity
  if (s >= 0) set[k] = s  // Infinity >= 0 is true, so size is set to Infinity
  break

The >= 0 guard was added to reject negative sizes. It does not enforce finiteness. The secondary guard notNegative() in src/header.ts has the same gap: Infinity < 0 is false, so it returns Infinity unchanged. As a result the entry's size becomes Infinity and reaches two distinct sinks: the parser body-length state machine and the numeric header encoder used during re-packing.

Impact

An unauthenticated remote attacker who can supply a tar archive to a consumer of this library obtains two demonstrated denial-of-service primitives, both from a single crafted archive with no user interaction:

  • Extraction / listing entry loss: when the Infinity-sized entry is parsed, the body-length counter becomes Infinity, the parser never transitions out of the body-consumption state, and every subsequent entry in the archive is silently consumed as body data. Extraction appears to succeed while dropping all following entries. A TAR_BAD_ARCHIVE warning is emitted only at end-of-archive and is ignored by consumers that do not run in strict mode.
  • Re-packing process crash: when entries read from the archive are piped back through the packer (for example via the supported tar.replace() / tar.update() @archive merge syntax, which calls pack.add(entry) on each existing entry), the Infinity size reaches the numeric header encoder, which throws Error("cannot encode number outside of javascript safe integer range") synchronously. The throw is not caught inside the packer, so it surfaces as an uncaught exception and terminates the process.

Both impacts were reproduced against the current published release. The re-packing crash is the worst credible outcome (loss of availability of the host process).

Proof of Concept

Runtime: Node.js >= 18. Package: tar (tested on the current published release).
Setup: build the library from source (npm install && npm run prepare) so the
compiled modules under dist/ are available, then run the script from the source root.

The crafted archive contains a PAX extended header that sets size=Infinity on the next file entry, followed by two ordinary file entries and the end-of-archive marker. The single PAX record 17 size=Infinity\n is exactly 17 bytes, matching its own length prefix, so it parses cleanly.

import { createRequire } from 'node:module';
import { resolve } from 'node:path';
const require = createRequire(resolve(process.cwd(), 'package.json'));
const { Header } = require('./dist/commonjs/header.js');
const { Parser } = require('./dist/commonjs/parse.js');
const { Pack } = require('./dist/commonjs/pack.js');

function block(fields, body = Buffer.alloc(0)) {
  const len = 512 * Math.ceil(1 + body.length / 512);
  const buf = Buffer.alloc(len);
  new Header(fields).encode(buf);
  body.copy(buf, 512);
  return buf;
}

const pax = block(
  { path: 'PaxHeader/x', mode: 0o644, size: 17, type: 'ExtendedHeader', mtime: new Date(0) },
  Buffer.from('17 size=Infinity\n'));
const f1 = block({ path: 'a.txt', mode: 0o644, size: 5, type: 'File', mtime: new Date(0) }, Buffer.from('hello'));
const f2 = block({ path: 'b.txt', mode: 0o644, size: 5, type: 'File', mtime: new Date(0) }, Buffer.from('world'));
const archive = Buffer.concat([pax, f1, f2, Buffer.alloc(1024)]);

// Impact 1: entry loss
let n = 0;
const p1 = new Parser({ strict: false });
p1.on('entry', e => { n++; e.resume(); });
p1.on('end', () => console.log('entries emitted:', n, '(expected 2)'));
p1.end(archive);

// Impact 2: uncaught synchronous throw when re-packing
const p2 = new Parser({ strict: false });
const pack = new Pack({ cwd: '/tmp' });
pack.on('data', () => {}); pack.on('error', () => {});
p2.on('entry', e => { try { pack.add(e); } catch (err) { console.log('throw:', err.message); e.resume(); } });
p2.end(archive);
entries emitted: 1 (expected 2)
throw: cannot encode number outside of javascript safe integer range

Attack Chain

  1. Exposure: The attacker supplies a tar archive to any consumer that parses, extracts, lists, or re-packs it. This is the ordinary, unauthenticated input to the library's public APIs.
  2. Control: The attacker fully controls the PAX extended-header record. The record 17 size=Infinity\n satisfies the length-prefix check (17 === Buffer.byteLength("17 size=Infinity") + 1), so it is parsed verbatim.
  3. Path: parseKVLine reaches the size case, computes +"Infinity" === Infinity, and the if (s >= 0) guard passes because Infinity >= 0 is true. The value flows through Header (notNegative(Infinity) === Infinity) into the read entry, where remain, startBlockSize, and blockRemain all become Infinity.
  4. Guard: The finiteness check that should exist on a size quantity is missing from both parseKVLine and notNegative(). The >= 0 check only rejects negatives; no check rejects Infinity, -Infinity, NaN, or values outside the safe-integer range.
  5. Primitive: In the parser, if (!entry.blockRemain) is !Infinity === false, so the parser never returns to the header state and consumes all remaining bytes as this entry's body. In the packing path, the numeric encoder receives Infinity, fails Number.isSafeInteger(Infinity), and throws synchronously with no surrounding catch.
  6. Result: Silent loss of every entry after the crafted one during extraction or listing, and an uncaught synchronous exception that crashes the host process during re-packing. Both are single-archive, no-interaction denial of service.

Bypass Evidence

The only relevant guard is the >= 0 size check (added to reject negative sizes) and its cousin notNegative(). Neither blocks this vector, verified against the runtime and the published source:

  • +"Infinity" === Infinity and Infinity >= 0 === true, so parseKVLine stores Infinity.
  • notNegative(Infinity) returns Infinity because Infinity < 0 is false.
  • !Infinity === false, so the parser body-state exit condition is never met.
  • Number.isSafeInteger(Infinity) === false, so the numeric encoder throws.

Disproof attempts that failed: the PAX header data size limit only bounds the extended-header block itself (17 bytes here), not the injected file size; the read-entry write-length check data.length > remain is always false against Infinity and never rejects data; no alternate parser state transition exists to recover from the stuck body state; and no try/catch exists anywhere along pack.add() to WriteEntryTar to numeric header encoding. This is not the previously fixed negative-size issue (that fix addressed a different input class, negative values) and it is not the NUL-byte string sanitization issue (that fix strips NUL bytes from string fields and has no effect on the string "Infinity", which contains no NUL). The affected field here is the numeric size, and the root cause is missing finiteness validation.

Affected Versions

  • Ecosystem: npm
  • Package: tar
  • Confirmed affected range: >= 7.0.0, <= 7.5.22
  • Latest release checked: 7.5.22 (npm registry, dist-tag latest)
  • Fix status: not fixed as of 7.5.22

The vulnerable numeric handling is present from 7.0.0 onward. In 7.0.0 through the release before the size guard was introduced, the string "Infinity" fell through the integer regex to the string branch, but downstream arithmetic (Math.ceil(Infinity / 512)) still produced Infinity with identical effects; from the guard-introducing release onward the value is explicitly coerced via +v and accepted by if (s >= 0). No published release adds a finiteness check. The legacy 6.x line contains the same unvalidated numeric parser but was not verified end to end and is not included in the confirmed range.

Suggested Fix

Enforce that a parsed size quantity is a finite, non-negative, representable integer at the parsing boundary, before it is stored and propagated. Extending the existing check to if (Number.isSafeInteger(s) && s >= 0) in the size case rejects Infinity, -Infinity, NaN, and out-of-range values at the source. Applying the same finiteness condition in notNegative() provides defense in depth for any other numeric field that reaches size-dependent arithmetic or header encoding. No configuration-only mitigation fully removes exposure; consumers who cannot upgrade should avoid re-packing untrusted archives and should run in strict mode so that the archive-integrity warning is surfaced as an error, though strict mode does not prevent the re-packing crash.


Reported by zx (GitHub: @manus-pi).

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "npm",
        "name": "tar"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "7.0.0"
            },
            {
              "fixed": "7.5.24"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-140242"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-1284"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-12-02T01:14:32Z",
    "nvd_published_at": "2026-12-01T18:17:28Z",
    "severity": "HIGH"
  },
  "details": "## Summary\n\n`tar` (node-tar) does not validate that a numeric `size` value supplied through a PAX extended header (typeflag `x`) is finite before it is applied to the following archive entry. A PAX record such as `17 size=Infinity\\n` is coerced to the JavaScript number `Infinity` and accepted, because the only guard on the value is a `\u003e= 0` check and `Infinity \u003e= 0` is true. The non-finite size then propagates into the entry-body state machine and, when the entry is re-packed, into numeric header encoding. Any process that parses, extracts, lists, or re-packs an attacker-supplied archive is affected; no authentication or non-default configuration is required.\n\n## Root Cause\n\nThe PAX key/value parser assigns the `size` field after a check that was designed only to reject negative values. It never checks that the coerced number is finite or a safe integer, so `Infinity` (and other non-finite positive values) pass.\n\n```typescript\n// src/pax.ts (parseKVLine)\ncase \u0027size\u0027:\n  const s = +v            // +\"Infinity\" === Infinity\n  if (s \u003e= 0) set[k] = s  // Infinity \u003e= 0 is true, so size is set to Infinity\n  break\n```\n\nThe `\u003e= 0` guard was added to reject negative sizes. It does not enforce finiteness. The secondary guard `notNegative()` in `src/header.ts` has the same gap: `Infinity \u003c 0` is false, so it returns `Infinity` unchanged. As a result the entry\u0027s `size` becomes `Infinity` and reaches two distinct sinks: the parser body-length state machine and the numeric header encoder used during re-packing.\n\n## Impact\n\nAn unauthenticated remote attacker who can supply a tar archive to a consumer of this library obtains two demonstrated denial-of-service primitives, both from a single crafted archive with no user interaction:\n\n- Extraction / listing entry loss: when the Infinity-sized entry is parsed, the body-length counter becomes `Infinity`, the parser never transitions out of the body-consumption state, and every subsequent entry in the archive is silently consumed as body data. Extraction appears to succeed while dropping all following entries. A `TAR_BAD_ARCHIVE` warning is emitted only at end-of-archive and is ignored by consumers that do not run in strict mode.\n- Re-packing process crash: when entries read from the archive are piped back through the packer (for example via the supported `tar.replace()` / `tar.update()` `@archive` merge syntax, which calls `pack.add(entry)` on each existing entry), the `Infinity` size reaches the numeric header encoder, which throws `Error(\"cannot encode number outside of javascript safe integer range\")` synchronously. The throw is not caught inside the packer, so it surfaces as an uncaught exception and terminates the process.\n\nBoth impacts were reproduced against the current published release. The re-packing crash is the worst credible outcome (loss of availability of the host process).\n\n## Proof of Concept\n\n```text\nRuntime: Node.js \u003e= 18. Package: tar (tested on the current published release).\nSetup: build the library from source (npm install \u0026\u0026 npm run prepare) so the\ncompiled modules under dist/ are available, then run the script from the source root.\n```\n\nThe crafted archive contains a PAX extended header that sets `size=Infinity` on the next file entry, followed by two ordinary file entries and the end-of-archive marker. The single PAX record `17 size=Infinity\\n` is exactly 17 bytes, matching its own length prefix, so it parses cleanly.\n\n```javascript\nimport { createRequire } from \u0027node:module\u0027;\nimport { resolve } from \u0027node:path\u0027;\nconst require = createRequire(resolve(process.cwd(), \u0027package.json\u0027));\nconst { Header } = require(\u0027./dist/commonjs/header.js\u0027);\nconst { Parser } = require(\u0027./dist/commonjs/parse.js\u0027);\nconst { Pack } = require(\u0027./dist/commonjs/pack.js\u0027);\n\nfunction block(fields, body = Buffer.alloc(0)) {\n  const len = 512 * Math.ceil(1 + body.length / 512);\n  const buf = Buffer.alloc(len);\n  new Header(fields).encode(buf);\n  body.copy(buf, 512);\n  return buf;\n}\n\nconst pax = block(\n  { path: \u0027PaxHeader/x\u0027, mode: 0o644, size: 17, type: \u0027ExtendedHeader\u0027, mtime: new Date(0) },\n  Buffer.from(\u002717 size=Infinity\\n\u0027));\nconst f1 = block({ path: \u0027a.txt\u0027, mode: 0o644, size: 5, type: \u0027File\u0027, mtime: new Date(0) }, Buffer.from(\u0027hello\u0027));\nconst f2 = block({ path: \u0027b.txt\u0027, mode: 0o644, size: 5, type: \u0027File\u0027, mtime: new Date(0) }, Buffer.from(\u0027world\u0027));\nconst archive = Buffer.concat([pax, f1, f2, Buffer.alloc(1024)]);\n\n// Impact 1: entry loss\nlet n = 0;\nconst p1 = new Parser({ strict: false });\np1.on(\u0027entry\u0027, e =\u003e { n++; e.resume(); });\np1.on(\u0027end\u0027, () =\u003e console.log(\u0027entries emitted:\u0027, n, \u0027(expected 2)\u0027));\np1.end(archive);\n\n// Impact 2: uncaught synchronous throw when re-packing\nconst p2 = new Parser({ strict: false });\nconst pack = new Pack({ cwd: \u0027/tmp\u0027 });\npack.on(\u0027data\u0027, () =\u003e {}); pack.on(\u0027error\u0027, () =\u003e {});\np2.on(\u0027entry\u0027, e =\u003e { try { pack.add(e); } catch (err) { console.log(\u0027throw:\u0027, err.message); e.resume(); } });\np2.end(archive);\n```\n\n```text\nentries emitted: 1 (expected 2)\nthrow: cannot encode number outside of javascript safe integer range\n```\n\n## Attack Chain\n\n1. **Exposure:** The attacker supplies a tar archive to any consumer that parses, extracts, lists, or re-packs it. This is the ordinary, unauthenticated input to the library\u0027s public APIs.\n2. **Control:** The attacker fully controls the PAX extended-header record. The record `17 size=Infinity\\n` satisfies the length-prefix check (`17 === Buffer.byteLength(\"17 size=Infinity\") + 1`), so it is parsed verbatim.\n3. **Path:** `parseKVLine` reaches the `size` case, computes `+\"Infinity\" === Infinity`, and the `if (s \u003e= 0)` guard passes because `Infinity \u003e= 0` is true. The value flows through `Header` (`notNegative(Infinity) === Infinity`) into the read entry, where `remain`, `startBlockSize`, and `blockRemain` all become `Infinity`.\n4. **Guard:** The finiteness check that should exist on a size quantity is missing from both `parseKVLine` and `notNegative()`. The `\u003e= 0` check only rejects negatives; no check rejects `Infinity`, `-Infinity`, `NaN`, or values outside the safe-integer range.\n5. **Primitive:** In the parser, `if (!entry.blockRemain)` is `!Infinity === false`, so the parser never returns to the header state and consumes all remaining bytes as this entry\u0027s body. In the packing path, the numeric encoder receives `Infinity`, fails `Number.isSafeInteger(Infinity)`, and throws synchronously with no surrounding catch.\n6. **Result:** Silent loss of every entry after the crafted one during extraction or listing, and an uncaught synchronous exception that crashes the host process during re-packing. Both are single-archive, no-interaction denial of service.\n\n## Bypass Evidence\n\nThe only relevant guard is the `\u003e= 0` size check (added to reject negative sizes) and its cousin `notNegative()`. Neither blocks this vector, verified against the runtime and the published source:\n\n- `+\"Infinity\" === Infinity` and `Infinity \u003e= 0 === true`, so `parseKVLine` stores `Infinity`.\n- `notNegative(Infinity)` returns `Infinity` because `Infinity \u003c 0` is false.\n- `!Infinity === false`, so the parser body-state exit condition is never met.\n- `Number.isSafeInteger(Infinity) === false`, so the numeric encoder throws.\n\nDisproof attempts that failed: the PAX header data size limit only bounds the extended-header block itself (17 bytes here), not the injected file size; the read-entry write-length check `data.length \u003e remain` is always false against `Infinity` and never rejects data; no alternate parser state transition exists to recover from the stuck body state; and no try/catch exists anywhere along `pack.add()` to `WriteEntryTar` to numeric header encoding. This is not the previously fixed negative-size issue (that fix addressed a different input class, negative values) and it is not the NUL-byte string sanitization issue (that fix strips NUL bytes from string fields and has no effect on the string `\"Infinity\"`, which contains no NUL). The affected field here is the numeric `size`, and the root cause is missing finiteness validation.\n\n## Affected Versions\n\n- `Ecosystem: npm`\n- `Package: tar`\n- `Confirmed affected range: \u003e= 7.0.0, \u003c= 7.5.22`\n- `Latest release checked: 7.5.22 (npm registry, dist-tag latest)`\n- `Fix status: not fixed as of 7.5.22`\n\nThe vulnerable numeric handling is present from 7.0.0 onward. In 7.0.0 through the release before the size guard was introduced, the string `\"Infinity\"` fell through the integer regex to the string branch, but downstream arithmetic (`Math.ceil(Infinity / 512)`) still produced `Infinity` with identical effects; from the guard-introducing release onward the value is explicitly coerced via `+v` and accepted by `if (s \u003e= 0)`. No published release adds a finiteness check. The legacy 6.x line contains the same unvalidated numeric parser but was not verified end to end and is not included in the confirmed range.\n\n## Suggested Fix\n\nEnforce that a parsed `size` quantity is a finite, non-negative, representable integer at the parsing boundary, before it is stored and propagated. Extending the existing check to `if (Number.isSafeInteger(s) \u0026\u0026 s \u003e= 0)` in the `size` case rejects `Infinity`, `-Infinity`, `NaN`, and out-of-range values at the source. Applying the same finiteness condition in `notNegative()` provides defense in depth for any other numeric field that reaches size-dependent arithmetic or header encoding. No configuration-only mitigation fully removes exposure; consumers who cannot upgrade should avoid re-packing untrusted archives and should run in strict mode so that the archive-integrity warning is surfaced as an error, though strict mode does not prevent the re-packing crash.\n\n---\n\nReported by zx (GitHub: @manus-pi).",
  "id": "GHSA-ph3c-p786-j4rp",
  "modified": "2026-12-02T01:14:32Z",
  "published": "2026-12-02T01:14:32Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/isaacs/node-tar/security/advisories/GHSA-ph3c-p786-j4rp"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-140242"
    },
    {
      "type": "WEB",
      "url": "https://github.com/isaacs/node-tar/commit/6b815b7c10be504a01af2369a270add7099542d8"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/isaacs/node-tar"
    },
    {
      "type": "WEB",
      "url": "https://github.com/isaacs/node-tar/releases/tag/v7.5.24"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N",
      "type": "CVSS_V4"
    }
  ],
  "summary": "node-tar: Non-finite PAX size (Infinity) bypasses validation, causing extraction entry loss and an uncaught exception when re-packing"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline

Sightings and recorded dates, grouped by day · UTC

JSON
How durations are calculated

Following the VTEM framework (Black Hat USA 2015), time to patch starts when the vendor or a coordinator was informed, total time to patch at discovery, and disclosure to patch at public disclosure; vendor response time runs from the report to its acknowledgement. Time to exploit and time unpatched start at the earliest discovery or report, falling back to public disclosure. Unpatched time ends at the first recorded patch, or the calculation time when no patch is recorded. Exploitation to patch shows the interval between those two events; a published proof of concept is a public exploit, not exploitation. The method is described in a publication.

Each result shows its source dates. A negative interval means the end event came first; when date-only inputs leave the order open, the result says so. Date-only inputs are approximate. The earliest evidence wins: KEV report dates and sightings are labelled as such. Records describing another vulnerability are listed but never calculated from, and a PoC alone does not establish exploitation. Missing patch evidence does not prove that no patch exists. Filters below change the event list only.

Events included in the timeline

Loading timeline…


    Loading…

    Loading…

    Loading…

    Related by attack behaviour

    Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.