From ea986fe970d61a05380251678ea6721c24a2d95c Mon Sep 17 00:00:00 2001 From: Michal Hruby Date: Sun, 25 Aug 2024 13:03:35 +0200 Subject: [PATCH 1/2] deal with missing zip64 flag --- lib/unzip-stream.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/unzip-stream.js b/lib/unzip-stream.js index 1a503b5..0a94da8 100644 --- a/lib/unzip-stream.js +++ b/lib/unzip-stream.js @@ -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 @@ -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; @@ -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) { zip64Mode = true; } + self.state = states.FILE_DATA_END; var sliceOffset = zip64Mode ? 24 : 16; if (self.data.length > 0) { From a43d0317f4dc1c35810cd35ead568f7068180ef1 Mon Sep 17 00:00:00 2001 From: Michal Hruby Date: Mon, 26 Aug 2024 09:00:23 +0200 Subject: [PATCH 2/2] Update lib/unzip-stream.js --- lib/unzip-stream.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/unzip-stream.js b/lib/unzip-stream.js index 0a94da8..5feaa67 100644 --- a/lib/unzip-stream.js +++ b/lib/unzip-stream.js @@ -341,7 +341,7 @@ 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) { zip64Mode = true; } + if (!zip64Mode && vars.uncompressedSize === 0 && vars.compressedSize >= 1024) { zip64Mode = true; } self.state = states.FILE_DATA_END; var sliceOffset = zip64Mode ? 24 : 16;