emit error on invalid header
This commit is contained in:
parent
931cb1f847
commit
81ddf7dcb6
2 changed files with 32 additions and 20 deletions
|
@ -75,7 +75,12 @@ var Extract = function(opts) {
|
|||
};
|
||||
|
||||
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);
|
||||
|
||||
if (!header) {
|
||||
|
|
13
headers.js
13
headers.js
|
@ -176,8 +176,6 @@ exports.decode = function(buf) {
|
|||
var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET;
|
||||
var type = toType(typeflag);
|
||||
|
||||
if (!type) return null;
|
||||
|
||||
var name = decodeStr(buf, 0, 100);
|
||||
var mode = decodeOct(buf, 100);
|
||||
var uid = decodeOct(buf, 108);
|
||||
|
@ -192,8 +190,13 @@ exports.decode = function(buf) {
|
|||
|
||||
if (buf[345]) name = decodeStr(buf, 345, 155)+'/'+name;
|
||||
|
||||
if (cksum(buf) !== decodeOct(buf, 148)) return null;
|
||||
var c = cksum(buf)
|
||||
|
||||
//checksum is still initial value if header was null.
|
||||
if (c === 8*32) return null;
|
||||
|
||||
//valid checksum
|
||||
if (c === decodeOct(buf, 148))
|
||||
return {
|
||||
name: name,
|
||||
mode: mode,
|
||||
|
@ -208,4 +211,8 @@ exports.decode = function(buf) {
|
|||
devmajor: devmajor,
|
||||
devminor: devminor
|
||||
};
|
||||
|
||||
//invalid checksum
|
||||
throw new Error('invalid header');
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue