From 58ff1564b72ac16e9d8f943dbcd7b4472827e8ea Mon Sep 17 00:00:00 2001 From: jbunton Date: Thu, 21 Apr 2016 15:48:51 +1000 Subject: [PATCH] Pack large UID and GIDs as 777777 --- headers.js | 4 +++- test/fixtures/index.js | 1 + test/fixtures/large-uid-gid.tar | Bin 0 -> 2048 bytes test/pack.js | 23 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/large-uid-gid.tar 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 0000000000000000000000000000000000000000..ae85a06ddff5a989b59587ab2ce4a764cf823159 GIT binary patch literal 2048 zcmXR(EiTb3sVHHfAuup7Ff%bxU@!**1Pv6207DZ6Ln9+oQ$rI|6C+av14AP-0|NyH z0~)#sZggpJNn#O$fkAF!8e9w;1E?$wp9+XifQ|+O1#CtPMzM_4oSb}x^8BKl6t2PO UzEL-ghQMeDjE2By2+$@30RIOXFaQ7m literal 0 HcmV?d00001 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()