Skip to content

Commit 2d89a4e

Browse files
committed
Properly handle long linkpath in PaxHeader
tar-stream creates some interesting tarballs, but they are technically allowed, and should be handled properly. Fix: isaacs#312 Also, this cleans up a flaky race condition in the unpack test.
1 parent 314ec7e commit 2d89a4e

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/parse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export class Parser extends EE implements Warner {
199199
})
200200
} else if (
201201
!/^(Symbolic)?Link$/.test(type) &&
202+
!/^(Global)?ExtendedHeader$/.test(type) &&
202203
header.linkpath
203204
) {
204205
this.warn('TAR_ENTRY_INVALID', 'linkpath forbidden', {

test/extract.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,3 +415,17 @@ t.test('brotli', async t => {
415415
t.end()
416416
})
417417
})
418+
419+
t.test('verify long linkname is not a problem', async t => {
420+
// See: https://github.com/isaacs/node-tar/issues/312
421+
const file = path.resolve(__dirname, 'fixtures/long-linkname.tar')
422+
t.test('sync', t => {
423+
x({ sync: true, strict: true, file, C: t.testdir({}) })
424+
t.ok(fs.lstatSync(t.testdirName + '/test').isSymbolicLink())
425+
t.end()
426+
})
427+
t.test('async', async t => {
428+
await x({ file, C: t.testdir({}), strict: true })
429+
t.ok(fs.lstatSync(t.testdirName + '/test').isSymbolicLink())
430+
})
431+
})

test/fixtures/long-linkname.tar

2.5 KB
Binary file not shown.

test/unpack.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,11 +1821,12 @@ t.test('set owner', t => {
18211821
if (!warned) {
18221822
warned = true
18231823
t.equal(er, poop)
1824-
t.end()
18251824
}
18261825
},
18271826
})
18281827
u.end(data)
1828+
t.equal(warned, true)
1829+
t.end()
18291830
})
18301831

18311832
t.test('async', t => {
@@ -1838,10 +1839,13 @@ t.test('set owner', t => {
18381839
if (!warned) {
18391840
warned = true
18401841
t.equal(er, poop)
1841-
t.end()
18421842
}
18431843
},
18441844
})
1845+
u.on('finish', () => {
1846+
t.equal(warned, true)
1847+
t.end()
1848+
})
18451849
u.end(data)
18461850
})
18471851

0 commit comments

Comments
 (0)