@zip.js/zip.js 2.18.0 → 2.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,6 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
- const VERSION = "2.18.0";
29
+ const VERSION = "2.18.1";
30
30
 
31
31
  export { VERSION };
@@ -1455,32 +1455,27 @@ async function detectOverlappingEntry({
1455
1455
  }) {
1456
1456
  let dataDescriptorLength = 0;
1457
1457
  if (dataDescriptor) {
1458
- if (extraFieldZip64) {
1459
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
1460
- } else {
1461
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
1462
- }
1463
- }
1464
- if (dataDescriptorLength) {
1465
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
1458
+ const zip64 = Boolean(extraFieldZip64);
1459
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
1466
1460
  const dataDescriptorView = getDataView(dataDescriptorArray);
1467
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
1468
- getUint32(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
1469
- if (signature) {
1470
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
1471
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
1472
- if (matchCrc32 &&
1473
- signedDataDescriptor.compressedSize == compressedSize &&
1474
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
1475
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
1476
- } else {
1477
- signature = false;
1461
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
1462
+ let localDataDescriptor;
1463
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
1464
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
1465
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
1466
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
1467
+ localDataDescriptor = candidate;
1468
+ break;
1478
1469
  }
1479
1470
  }
1480
- if (dataDescriptorArray.length >= dataDescriptorLength) {
1481
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
1482
- localDataDescriptor.signature = signature;
1471
+ if (!localDataDescriptor) {
1472
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
1473
+ }
1474
+ if (localDataDescriptor) {
1483
1475
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
1476
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
1477
+ } else {
1478
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
1484
1479
  }
1485
1480
  }
1486
1481
  const range = {
@@ -1545,18 +1540,31 @@ function mergeRanges(sortedRanges, pendingRanges) {
1545
1540
  return mergedRanges;
1546
1541
  }
1547
1542
 
1548
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
1543
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
1544
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
1545
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
1546
+ (signature && getUint32(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
1547
+ return UNDEFINED_VALUE;
1548
+ }
1549
1549
  const crc32 = getUint32(dataDescriptorView, offset);
1550
1550
  let compressedSize;
1551
1551
  let uncompressedSize;
1552
- if (extraFieldZip64) {
1553
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
1554
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
1555
- } else {
1556
- compressedSize = getUint32(dataDescriptorView, offset + 4);
1557
- uncompressedSize = getUint32(dataDescriptorView, offset + 8);
1552
+ try {
1553
+ if (zip64) {
1554
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
1555
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
1556
+ } else {
1557
+ compressedSize = getUint32(dataDescriptorView, offset + 4);
1558
+ uncompressedSize = getUint32(dataDescriptorView, offset + 8);
1559
+ }
1560
+ } catch {
1561
+ return UNDEFINED_VALUE;
1558
1562
  }
1559
- return { crc32, compressedSize, uncompressedSize };
1563
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
1564
+ }
1565
+
1566
+ function getDataDescriptorLength(zip64, signature) {
1567
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
1560
1568
  }
1561
1569
 
1562
1570
  function getDiskOffset(reader, diskNumber) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.18.0",
6
+ "version": "2.18.1",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",