Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed incorrect offset value for files in ZIP after 4GB #139

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class Entry {
return this.dataView.getUint32(20, true);
}

get uncompressedSize() {
return this.dataView.getUint32(24, true);
}

get filenameLength() {
return this.dataView.getUint16(28, true);
}
Expand Down Expand Up @@ -98,11 +102,26 @@ class Entry {
}

get offset() {
return this.dataView.getUint32(42, true);
if (this.zip64) {
// Read the ZIP64 offset from the extra fields
// The extra field 0x0001 is used for ZIP64 information
const extraField = this._extraFields[0x0001];
if (extraField) {
// The offset is the third field in the ZIP64 extra fields
const offset = (this.compressedSize === MAX_VALUE_32BITS ? 8 : 0) + (this.uncompressedSize === MAX_VALUE_32BITS ? 8 : 0);
return JSBI.toNumber(getBigInt64(extraField, offset, true));
} else {
throw new Error('ZIP64 extra field missing');
}
} else {
return this.dataView.getUint32(42, true);
}
}

get zip64() {
return this.dataView.getUint32(24, true) === MAX_VALUE_32BITS;
return this.compressedSize === MAX_VALUE_32BITS
|| this.uncompressedSize === MAX_VALUE_32BITS
|| this.dataView.getUint32(42, true) === MAX_VALUE_32BITS;
}

get comment() {
Expand Down Expand Up @@ -150,8 +169,8 @@ class Entry {
}

get size() {
const size = this.dataView.getUint32(24, true);
return size === MAX_VALUE_32BITS ? this._extraFields[1].getUint8(0) : size;
const size = this.uncompressedSize;
return size === MAX_VALUE_32BITS ? JSBI.toNumber(getBigInt64(this._extraFields[0x0001], 0)) : size;
}

stream() {
Expand Down