bower / decompress-zip

Module that decompresses zip files
MIT License
102 stars 76 forks source link

RangeError: Trying to access beyond buffer length #16

Closed monkeycraps closed 10 years ago

monkeycraps commented 10 years ago

for a zip file with 273 files, it emit such an error. is there any way to deal with?

on the side, is there a function get zip entry as java zip lib?

thanks for reply

monkeycraps commented 10 years ago

hi, i found it is a bug when extra filed is less then 4 bytes:

when u parsing entity with function structures.readFileEntity

u caculate the extra as follow fileEntry.extraField = parseExtraFields(buffer.slice(index, index + fileEntry.extraFieldLength));

which will do as bellow, for the extra field witch is less then 4 bytes, it will throw error as issue title

` var parseExtraFields = function (buffer) { var index = 0;

var fields = {};

while (index < buffer.length) {
    var header = buffer.readUInt16LE(index);
    var length = buffer.readUInt16LE(index + 2);
    var field = buffer.slice(index + 4, index + 4 + length);

    // TODO: Actually do something with this data
    fields[header] = field;

    index += length + 4;
}

return fields;

}; `

wibblymat commented 10 years ago

It looks like you are using an out of date version. Could you try it on the same zip with version 0.0.3?