diff --git a/.gitignore b/.gitignore index cd38f37..4674b2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules test/fixtures/copy test/fixtures/invalid +test/fixtures/outside diff --git a/test/index.js b/test/index.js index 3129eb7..a03844e 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,7 @@ var test = require('tape') var rimraf = require('rimraf') var tar = require('../index') +var tarStream = require('tar-stream') var path = require('path') var fs = require('fs') var os = require('os') @@ -310,3 +311,36 @@ test('do not extract invalid tar', function (t) { }) }) }) + +test('no abs hardlink targets', function (t) { + var out = path.join(__dirname, 'fixtures', 'invalid') + var outside = path.join(__dirname, 'fixtures', 'outside') + + rimraf.sync(out) + + var s = tarStream.pack() + + fs.writeFileSync(outside, 'something') + + s.entry({ + type: 'link', + name: 'link', + linkname: outside + }) + + s.entry({ + name: 'link' + }, 'overwrite') + + s.finalize() + + s.pipe(tar.extract(out)) + .on('error', function (err) { + t.ok(err, 'had error') + fs.readFile(outside, 'utf-8', function (err, str) { + t.error(err, 'no error') + t.same(str, 'something') + t.end() + }) + }) +})