jszip
jszip copied to clipboard
Uncompressed data size mismatch (nodejs) still there in 3.7.1 - 32 Bit Issue with <<
trafficstars
I got a ZIP which includes a single file with more than 2GB in (decompressed) size. On decompression the error from the title is thrown. It clearly is some 32Bit signed/unsigned issue:
worker.on("end", function () {
if (this.streamInfo['data_length'] !== that.uncompressedSize) {
throw new Error("Bug : uncompressed data size mismatch");
}
});
this.streamInfo['data_length']
4011341711 (0xEF18378F)
that.uncompressedSize
-283625585 (0xEF18378F)
So my question is: is there a size limit of 2GB for individual files inside the ZIP (which by the way has been created with jszip 3.7.1 as well)?
Thanks
Jochen
Problem is that << only reproduces 32 Bit Value, so
readInt: function(size) {
var result = 0,
i;
this.checkOffset(size);
for (i = this.index + size - 1; i >= this.index; i--) {
result = (result << 8) + this.byteAt(i);
}
this.index += size;
return result;
},
will mess with the sign if the MSB is larger than 127. Better use multiplication
readInt: function(size) {
var result = 0,
i;
this.checkOffset(size);
for (i = this.index + size - 1; i >= this.index; i--) {
result = (result * 256) + this.byteAt(i);
}
this.index += size;
return result;
},
FYI: * 256 will be safe up to 53 Bit (MAX_SAFE_INTEGER) which is around 9 PetaByte.
We are also affected.