@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.
@@ -6025,32 +6025,27 @@
6025
6025
  }) {
6026
6026
  let dataDescriptorLength = 0;
6027
6027
  if (dataDescriptor) {
6028
- if (extraFieldZip64) {
6029
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6030
- } else {
6031
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6032
- }
6033
- }
6034
- if (dataDescriptorLength) {
6035
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6028
+ const zip64 = Boolean(extraFieldZip64);
6029
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6036
6030
  const dataDescriptorView = getDataView(dataDescriptorArray);
6037
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6038
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6039
- if (signature) {
6040
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6041
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6042
- if (matchCrc32 &&
6043
- signedDataDescriptor.compressedSize == compressedSize &&
6044
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6045
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6046
- } else {
6047
- signature = false;
6031
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
6032
+ let localDataDescriptor;
6033
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
6034
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
6035
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
6036
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
6037
+ localDataDescriptor = candidate;
6038
+ break;
6048
6039
  }
6049
6040
  }
6050
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6051
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6052
- localDataDescriptor.signature = signature;
6041
+ if (!localDataDescriptor) {
6042
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
6043
+ }
6044
+ if (localDataDescriptor) {
6053
6045
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6046
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6047
+ } else {
6048
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6054
6049
  }
6055
6050
  }
6056
6051
  const range = {
@@ -6115,18 +6110,31 @@
6115
6110
  return mergedRanges;
6116
6111
  }
6117
6112
 
6118
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6113
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6114
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6115
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6116
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6117
+ return UNDEFINED_VALUE;
6118
+ }
6119
6119
  const crc32 = getUint32$1(dataDescriptorView, offset);
6120
6120
  let compressedSize;
6121
6121
  let uncompressedSize;
6122
- if (extraFieldZip64) {
6123
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6124
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6125
- } else {
6126
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6127
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6122
+ try {
6123
+ if (zip64) {
6124
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6125
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6126
+ } else {
6127
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6128
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6129
+ }
6130
+ } catch {
6131
+ return UNDEFINED_VALUE;
6128
6132
  }
6129
- return { crc32, compressedSize, uncompressedSize };
6133
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6134
+ }
6135
+
6136
+ function getDataDescriptorLength(zip64, signature) {
6137
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6130
6138
  }
6131
6139
 
6132
6140
  function getDiskOffset$1(reader, diskNumber) {
@@ -9047,7 +9055,7 @@
9047
9055
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9048
9056
  */
9049
9057
 
9050
- const VERSION = "2.18.0";
9058
+ const VERSION = "2.18.1";
9051
9059
 
9052
9060
  /*
9053
9061
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.