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