@zip.js/zip.js 2.18.0 → 2.18.2

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,19 @@
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;
6048
- }
6049
- }
6050
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6051
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6052
- localDataDescriptor.signature = signature;
6031
+ const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
6032
+ .map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
6033
+ .filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
6034
+ const localDataDescriptor = candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
6035
+ readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
6036
+ if (localDataDescriptor) {
6053
6037
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6038
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6039
+ } else {
6040
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6054
6041
  }
6055
6042
  }
6056
6043
  const range = {
@@ -6115,18 +6102,31 @@
6115
6102
  return mergedRanges;
6116
6103
  }
6117
6104
 
6118
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6105
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6106
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6107
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6108
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6109
+ return UNDEFINED_VALUE;
6110
+ }
6119
6111
  const crc32 = getUint32$1(dataDescriptorView, offset);
6120
6112
  let compressedSize;
6121
6113
  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);
6114
+ try {
6115
+ if (zip64) {
6116
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6117
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6118
+ } else {
6119
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6120
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6121
+ }
6122
+ } catch {
6123
+ return UNDEFINED_VALUE;
6128
6124
  }
6129
- return { crc32, compressedSize, uncompressedSize };
6125
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6126
+ }
6127
+
6128
+ function getDataDescriptorLength(zip64, signature) {
6129
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6130
6130
  }
6131
6131
 
6132
6132
  function getDiskOffset$1(reader, diskNumber) {
@@ -9047,7 +9047,7 @@
9047
9047
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9048
9048
  */
9049
9049
 
9050
- const VERSION = "2.18.0";
9050
+ const VERSION = "2.18.2";
9051
9051
 
9052
9052
  /*
9053
9053
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.