Merge pull request #11 from dominictarr/master
emit error on invalid header
This commit is contained in:
commit
37a497ff7e
2 changed files with 32 additions and 20 deletions
|
@ -75,7 +75,12 @@ var Extract = function(opts) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var onheader = function() {
|
var onheader = function() {
|
||||||
var header = self._header = headers.decode(b.slice(0, 512));
|
var header
|
||||||
|
try {
|
||||||
|
header = self._header = headers.decode(b.slice(0, 512));
|
||||||
|
} catch (err) {
|
||||||
|
self.emit('error', err)
|
||||||
|
}
|
||||||
b.consume(512);
|
b.consume(512);
|
||||||
|
|
||||||
if (!header) {
|
if (!header) {
|
||||||
|
|
41
headers.js
41
headers.js
|
@ -176,8 +176,6 @@ exports.decode = function(buf) {
|
||||||
var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET;
|
var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET;
|
||||||
var type = toType(typeflag);
|
var type = toType(typeflag);
|
||||||
|
|
||||||
if (!type) return null;
|
|
||||||
|
|
||||||
var name = decodeStr(buf, 0, 100);
|
var name = decodeStr(buf, 0, 100);
|
||||||
var mode = decodeOct(buf, 100);
|
var mode = decodeOct(buf, 100);
|
||||||
var uid = decodeOct(buf, 108);
|
var uid = decodeOct(buf, 108);
|
||||||
|
@ -192,20 +190,29 @@ exports.decode = function(buf) {
|
||||||
|
|
||||||
if (buf[345]) name = decodeStr(buf, 345, 155)+'/'+name;
|
if (buf[345]) name = decodeStr(buf, 345, 155)+'/'+name;
|
||||||
|
|
||||||
if (cksum(buf) !== decodeOct(buf, 148)) return null;
|
var c = cksum(buf)
|
||||||
|
|
||||||
return {
|
//checksum is still initial value if header was null.
|
||||||
name: name,
|
if (c === 8*32) return null;
|
||||||
mode: mode,
|
|
||||||
uid: uid,
|
//valid checksum
|
||||||
gid: gid,
|
if (c === decodeOct(buf, 148))
|
||||||
size: size,
|
return {
|
||||||
mtime: new Date(1000 * mtime),
|
name: name,
|
||||||
type: toType(typeflag),
|
mode: mode,
|
||||||
linkname: linkname,
|
uid: uid,
|
||||||
uname: uname,
|
gid: gid,
|
||||||
gname: gname,
|
size: size,
|
||||||
devmajor: devmajor,
|
mtime: new Date(1000 * mtime),
|
||||||
devminor: devminor
|
type: toType(typeflag),
|
||||||
};
|
linkname: linkname,
|
||||||
|
uname: uname,
|
||||||
|
gname: gname,
|
||||||
|
devmajor: devmajor,
|
||||||
|
devminor: devminor
|
||||||
|
};
|
||||||
|
|
||||||
|
//invalid checksum
|
||||||
|
throw new Error('invalid header');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue