@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.
@@ -6005,32 +6005,27 @@
6005
6005
  }) {
6006
6006
  let dataDescriptorLength = 0;
6007
6007
  if (dataDescriptor) {
6008
- if (extraFieldZip64) {
6009
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6010
- } else {
6011
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6012
- }
6013
- }
6014
- if (dataDescriptorLength) {
6015
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6008
+ const zip64 = Boolean(extraFieldZip64);
6009
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6016
6010
  const dataDescriptorView = getDataView(dataDescriptorArray);
6017
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6018
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6019
- if (signature) {
6020
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6021
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6022
- if (matchCrc32 &&
6023
- signedDataDescriptor.compressedSize == compressedSize &&
6024
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6025
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6026
- } else {
6027
- signature = false;
6011
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
6012
+ let localDataDescriptor;
6013
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
6014
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
6015
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
6016
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
6017
+ localDataDescriptor = candidate;
6018
+ break;
6028
6019
  }
6029
6020
  }
6030
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6031
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6032
- localDataDescriptor.signature = signature;
6021
+ if (!localDataDescriptor) {
6022
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
6023
+ }
6024
+ if (localDataDescriptor) {
6033
6025
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6026
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6027
+ } else {
6028
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6034
6029
  }
6035
6030
  }
6036
6031
  const range = {
@@ -6095,18 +6090,31 @@
6095
6090
  return mergedRanges;
6096
6091
  }
6097
6092
 
6098
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6093
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6094
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6095
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6096
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6097
+ return UNDEFINED_VALUE;
6098
+ }
6099
6099
  const crc32 = getUint32$1(dataDescriptorView, offset);
6100
6100
  let compressedSize;
6101
6101
  let uncompressedSize;
6102
- if (extraFieldZip64) {
6103
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6104
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6105
- } else {
6106
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6107
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6102
+ try {
6103
+ if (zip64) {
6104
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6105
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6106
+ } else {
6107
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6108
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6109
+ }
6110
+ } catch {
6111
+ return UNDEFINED_VALUE;
6108
6112
  }
6109
- return { crc32, compressedSize, uncompressedSize };
6113
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6114
+ }
6115
+
6116
+ function getDataDescriptorLength(zip64, signature) {
6117
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6110
6118
  }
6111
6119
 
6112
6120
  function getDiskOffset$1(reader, diskNumber) {
@@ -8929,7 +8937,7 @@
8929
8937
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8930
8938
  */
8931
8939
 
8932
- const VERSION = "2.18.0";
8940
+ const VERSION = "2.18.1";
8933
8941
 
8934
8942
  /*
8935
8943
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.