Skip to content

Commit

Permalink
fixes #324 - parsing of ZIP64 extra entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Benndorf committed Jul 4, 2024
1 parent 4ffedb7 commit a8b057f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/parseExtraField.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ module.exports = function(extraField, vars) {
while(!extra && extraField && extraField.length) {
const candidateExtra = parseBuffer.parse(extraField, [
['signature', 2],
['partsize', 2],
['uncompressedSize', 8],
['compressedSize', 8],
['offset', 8],
['disknum', 8],
['partSize', 2],
]);

if(candidateExtra.signature === 0x0001) {
extra = candidateExtra;
// parse buffer based on data in ZIP64 central directory; order is important!
const fieldsToExpect = [];
if (vars.uncompressedSize === 0xffffffff) fieldsToExpect.push(['uncompressedSize', 8]);
if (vars.compressedSize === 0xffffffff) fieldsToExpect.push(['compressedSize', 8]);
if (vars.offsetToLocalFileHeader === 0xffffffff) fieldsToExpect.push(['offsetToLocalFileHeader', 8]);

// slice off the 4 bytes for signature and partSize
extra = parseBuffer.parse(extraField.slice(4), fieldsToExpect);
} else {
// Advance the buffer to the next part.
// The total size of this part is the 4 byte header + partsize.
extraField = extraField.slice(candidateExtra.partsize + 4);
extraField = extraField.slice(candidateExtra.partSize + 4);
}
}

Expand All @@ -31,7 +34,7 @@ module.exports = function(extraField, vars) {
vars.uncompressedSize= extra.uncompressedSize;

if (vars.offsetToLocalFileHeader === 0xffffffff)
vars.offsetToLocalFileHeader= extra.offset;
vars.offsetToLocalFileHeader = extra.offsetToLocalFileHeader;

return extra;
};

0 comments on commit a8b057f

Please sign in to comment.