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