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

deal with missing zip64 flag #53

Open
wants to merge 2 commits into
base: master
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
15 changes: 14 additions & 1 deletion lib/unzip-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ UnzipStream.prototype._prepareOutStream = function (vars, entry) {
var pattern = new Buffer(4);
pattern.writeUInt32LE(SIG_DATA_DESCRIPTOR, 0);
var zip64Mode = vars.extra.zip64Mode;
var extraSize = zip64Mode ? 20 : 12;
var extraSize = 20; // should be just 12 when !zip64Mode, but we'll put it back
var searchPattern = {
pattern: pattern,
requiredExtraSize: extraSize
Expand All @@ -319,6 +319,16 @@ UnzipStream.prototype._prepareOutStream = function (vars, entry) {
var vars = self._readDataDescriptor(matchedChunk, zip64Mode);

var compressedSizeMatches = vars.compressedSize === sizeSoFar;
// sometimes the local header is missing the zip64 flag
if (!zip64Mode && !compressedSizeMatches && sizeSoFar >= FOUR_GIGS) {
// try to read the 64bit data descriptor
var vars64 = self._readDataDescriptor(matchedChunk, true);
if (vars64.compressedSize === sizeSoFar) {
compressedSizeMatches = true;
zip64Mode = true;
vars = vars64;
}
}
// let's also deal with archives with 4GiB+ files without zip64
if (!zip64Mode && !compressedSizeMatches && sizeSoFar >= FOUR_GIGS) {
var overflown = sizeSoFar - FOUR_GIGS;
Expand All @@ -330,6 +340,9 @@ UnzipStream.prototype._prepareOutStream = function (vars, entry) {
}
if (!compressedSizeMatches) { return; }

// check for zero uncompressedSize, which means the local header is missing the zip64 flag
if (!zip64Mode && vars.uncompressedSize === 0 && vars.compressedSize >= 1024) { zip64Mode = true; }

self.state = states.FILE_DATA_END;
var sliceOffset = zip64Mode ? 24 : 16;
if (self.data.length > 0) {
Expand Down