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