GitHub advisory · npm
node-tar: Non-finite PAX size (Infinity) bypasses validation, causing extraction entry loss and an uncaught exception when re-packing
Description
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.
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.
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:
Infinity, the parser never transitions out of the body-consumption state, and every subsequent entry in the archive is silently consumed as body…Manual fix · npm
npm install tar@7.5.24Sources