@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.
package/dist/zip-fs.js CHANGED
@@ -6033,32 +6033,19 @@
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;
6056
- }
6057
- }
6058
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6059
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6060
- localDataDescriptor.signature = signature;
6039
+ const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
6040
+ .map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
6041
+ .filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
6042
+ const localDataDescriptor = candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
6043
+ readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
6044
+ if (localDataDescriptor) {
6061
6045
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6046
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6047
+ } else {
6048
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6062
6049
  }
6063
6050
  }
6064
6051
  const range = {
@@ -6123,18 +6110,31 @@
6123
6110
  return mergedRanges;
6124
6111
  }
6125
6112
 
6126
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6113
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6114
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6115
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6116
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6117
+ return UNDEFINED_VALUE;
6118
+ }
6127
6119
  const crc32 = getUint32$1(dataDescriptorView, offset);
6128
6120
  let compressedSize;
6129
6121
  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);
6122
+ try {
6123
+ if (zip64) {
6124
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6125
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6126
+ } else {
6127
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6128
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6129
+ }
6130
+ } catch {
6131
+ return UNDEFINED_VALUE;
6136
6132
  }
6137
- return { crc32, compressedSize, uncompressedSize };
6133
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6134
+ }
6135
+
6136
+ function getDataDescriptorLength(zip64, signature) {
6137
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6138
6138
  }
6139
6139
 
6140
6140
  function getDiskOffset$1(reader, diskNumber) {
@@ -9055,7 +9055,7 @@
9055
9055
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9056
9056
  */
9057
9057
 
9058
- const VERSION = "2.18.0";
9058
+ const VERSION = "2.18.2";
9059
9059
 
9060
9060
  /*
9061
9061
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.