@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-fs.js CHANGED
@@ -6033,32 +6033,27 @@
6033
6033
  }) {
6034
6034
  let dataDescriptorLength = 0;
6035
6035
  if (dataDescriptor) {
6036
- if (extraFieldZip64) {
6037
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6038
- } else {
6039
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6040
- }
6041
- }
6042
- if (dataDescriptorLength) {
6043
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6036
+ const zip64 = Boolean(extraFieldZip64);
6037
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6044
6038
  const dataDescriptorView = getDataView(dataDescriptorArray);
6045
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6046
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6047
- if (signature) {
6048
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6049
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6050
- if (matchCrc32 &&
6051
- signedDataDescriptor.compressedSize == compressedSize &&
6052
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6053
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6054
- } else {
6055
- signature = false;
6039
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
6040
+ let localDataDescriptor;
6041
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
6042
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
6043
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
6044
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
6045
+ localDataDescriptor = candidate;
6046
+ break;
6056
6047
  }
6057
6048
  }
6058
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6059
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6060
- localDataDescriptor.signature = signature;
6049
+ if (!localDataDescriptor) {
6050
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
6051
+ }
6052
+ if (localDataDescriptor) {
6061
6053
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6054
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6055
+ } else {
6056
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6062
6057
  }
6063
6058
  }
6064
6059
  const range = {
@@ -6123,18 +6118,31 @@
6123
6118
  return mergedRanges;
6124
6119
  }
6125
6120
 
6126
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6121
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6122
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6123
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6124
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6125
+ return UNDEFINED_VALUE;
6126
+ }
6127
6127
  const crc32 = getUint32$1(dataDescriptorView, offset);
6128
6128
  let compressedSize;
6129
6129
  let uncompressedSize;
6130
- if (extraFieldZip64) {
6131
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6132
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6133
- } else {
6134
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6135
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6130
+ try {
6131
+ if (zip64) {
6132
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6133
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6134
+ } else {
6135
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6136
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6137
+ }
6138
+ } catch {
6139
+ return UNDEFINED_VALUE;
6136
6140
  }
6137
- return { crc32, compressedSize, uncompressedSize };
6141
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6142
+ }
6143
+
6144
+ function getDataDescriptorLength(zip64, signature) {
6145
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6138
6146
  }
6139
6147
 
6140
6148
  function getDiskOffset$1(reader, diskNumber) {
@@ -9055,7 +9063,7 @@
9055
9063
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9056
9064
  */
9057
9065
 
9058
- const VERSION = "2.18.0";
9066
+ const VERSION = "2.18.1";
9059
9067
 
9060
9068
  /*
9061
9069
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.