diff --git a/headers.js b/headers.js index 5ea4333..42f8c6a 100644 --- a/headers.js +++ b/headers.js @@ -90,6 +90,9 @@ var encodeOct = function(val, n) { }; var decodeOct = function(val, offset) { + // Older versions of tar can prefix with spaces + while (val[offset] === 32) offset += 1; + return parseInt(val.slice(offset, clamp(indexOf(val, 32, offset, val.length), val.length, val.length)).toString(), 8); }; diff --git a/test/extract.js b/test/extract.js index 27c6310..e758b27 100644 --- a/test/extract.js +++ b/test/extract.js @@ -417,4 +417,21 @@ test('invalid-file', function(t) { }); extract.end(fs.readFileSync(fixtures.INVALID_TGZ)); -}); \ No newline at end of file +}); + +test('space prefixed', function(t) { + t.plan(5); + + var extract = tar.extract(); + + extract.on('entry', function(header, stream, callback) { + t.ok(true) + callback(); + }); + + extract.on('finish', function() { + t.ok(true); + }); + + extract.end(fs.readFileSync(fixtures.SPACE_TAR_GZ)); +}); diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 59bc87b..0c4b283 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -7,4 +7,5 @@ exports.LONG_NAME_TAR = path.join(__dirname, 'long-name.tar'); exports.UNICODE_BSD_TAR = path.join(__dirname, 'unicode-bsd.tar'); exports.UNICODE_TAR = path.join(__dirname, 'unicode.tar'); exports.NAME_IS_100_TAR = path.join(__dirname, 'name-is-100.tar'); -exports.INVALID_TGZ = path.join(__dirname, 'invalid.tgz'); \ No newline at end of file +exports.INVALID_TGZ = path.join(__dirname, 'invalid.tgz'); +exports.SPACE_TAR_GZ = path.join(__dirname, 'space.tar'); diff --git a/test/fixtures/space.tar b/test/fixtures/space.tar new file mode 100644 index 0000000..0bd7cea Binary files /dev/null and b/test/fixtures/space.tar differ