diff --git a/headers.js b/headers.js index d786148..8aab8b5 100644 --- a/headers.js +++ b/headers.js @@ -132,10 +132,13 @@ function parse256 (buf) { return positive ? sum : -1 * sum } -var decodeOct = function (val, offset) { +var decodeOct = function (val, offset, length) { + val = val.slice(offset, offset + length) + offset = 0 + // If prefixed with 0x80 then parse as a base-256 integer if (val[offset] & 0x80) { - return parse256(val.slice(offset, offset + 8)) + return parse256(val) } else { // Older versions of tar can prefix with spaces while (offset < val.length && val[offset] === 32) offset++ @@ -241,17 +244,17 @@ exports.decode = function (buf) { var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET var name = decodeStr(buf, 0, 100) - var mode = decodeOct(buf, 100) - var uid = decodeOct(buf, 108) - var gid = decodeOct(buf, 116) - var size = decodeOct(buf, 124) - var mtime = decodeOct(buf, 136) + var mode = decodeOct(buf, 100, 8) + var uid = decodeOct(buf, 108, 8) + var gid = decodeOct(buf, 116, 8) + var size = decodeOct(buf, 124, 12) + var mtime = decodeOct(buf, 136, 12) var type = toType(typeflag) var linkname = buf[157] === 0 ? null : decodeStr(buf, 157, 100) var uname = decodeStr(buf, 265, 32) var gname = decodeStr(buf, 297, 32) - var devmajor = decodeOct(buf, 329) - var devminor = decodeOct(buf, 337) + var devmajor = decodeOct(buf, 329, 8) + var devminor = decodeOct(buf, 337, 8) if (buf[345]) name = decodeStr(buf, 345, 155) + '/' + name @@ -264,7 +267,7 @@ exports.decode = function (buf) { if (c === 8 * 32) return null // valid checksum - if (c !== decodeOct(buf, 148)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?') + if (c !== decodeOct(buf, 148, 8)) throw new Error('Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?') return { name: name,