diff --git a/headers.js b/headers.js index 8c75edc..d786148 100644 --- a/headers.js +++ b/headers.js @@ -1,4 +1,5 @@ var ZEROS = '0000000000000000000' +var SEVENS = '7777777777777777777' var ZERO_OFFSET = '0'.charCodeAt(0) var USTAR = 'ustar\x0000' var MASK = parseInt('7777', 8) @@ -92,7 +93,8 @@ var cksum = function (block) { var encodeOct = function (val, n) { val = val.toString(8) - return ZEROS.slice(0, n - val.length) + val + ' ' + if (val.length > n) return SEVENS.slice(0, n) + ' ' + else return ZEROS.slice(0, n - val.length) + val + ' ' } /* Copied from the node-tar repo and modified to meet diff --git a/test/fixtures/index.js b/test/fixtures/index.js index eb18dbd..4e686bd 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -12,3 +12,4 @@ exports.INVALID_TGZ = path.join(__dirname, 'invalid.tgz') exports.SPACE_TAR_GZ = path.join(__dirname, 'space.tar') exports.GNU_LONG_PATH = path.join(__dirname, 'gnu-long-path.tar') exports.BASE_256_UID_GID = path.join(__dirname, 'base-256-uid-gid.tar') +exports.LARGE_UID_GID = path.join(__dirname, 'large-uid-gid.tar') diff --git a/test/fixtures/large-uid-gid.tar b/test/fixtures/large-uid-gid.tar new file mode 100644 index 0000000..ae85a06 Binary files /dev/null and b/test/fixtures/large-uid-gid.tar differ diff --git a/test/pack.js b/test/pack.js index 49f7a90..946879e 100644 --- a/test/pack.js +++ b/test/pack.js @@ -145,6 +145,29 @@ test('long-name', function (t) { })) }) +test('large-uid-gid', function (t) { + t.plan(2) + var pack = tar.pack() + + pack.entry({ + name: 'test.txt', + mtime: new Date(1387580181000), + mode: parseInt('644', 8), + uname: 'maf', + gname: 'staff', + uid: 1000000001, + gid: 1000000002 + }, 'hello world\n') + + pack.finalize() + + pack.pipe(concat(function (data) { + t.same(data.length & 511, 0) + t.deepEqual(data, fs.readFileSync(fixtures.LARGE_UID_GID)) + fs.writeFileSync('/tmp/foo', data) + })) +}) + test('unicode', function (t) { t.plan(2) var pack = tar.pack()