@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.
@@ -6058,32 +6058,27 @@ async function detectOverlappingEntry({
6058
6058
  }) {
6059
6059
  let dataDescriptorLength = 0;
6060
6060
  if (dataDescriptor) {
6061
- if (extraFieldZip64) {
6062
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6063
- } else {
6064
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6065
- }
6066
- }
6067
- if (dataDescriptorLength) {
6068
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6061
+ const zip64 = Boolean(extraFieldZip64);
6062
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6069
6063
  const dataDescriptorView = getDataView(dataDescriptorArray);
6070
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6071
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6072
- if (signature) {
6073
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6074
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6075
- if (matchCrc32 &&
6076
- signedDataDescriptor.compressedSize == compressedSize &&
6077
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6078
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6079
- } else {
6080
- signature = false;
6064
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
6065
+ let localDataDescriptor;
6066
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
6067
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
6068
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
6069
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
6070
+ localDataDescriptor = candidate;
6071
+ break;
6081
6072
  }
6082
6073
  }
6083
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6084
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6085
- localDataDescriptor.signature = signature;
6074
+ if (!localDataDescriptor) {
6075
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
6076
+ }
6077
+ if (localDataDescriptor) {
6086
6078
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6079
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6080
+ } else {
6081
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6087
6082
  }
6088
6083
  }
6089
6084
  const range = {
@@ -6148,18 +6143,31 @@ function mergeRanges(sortedRanges, pendingRanges) {
6148
6143
  return mergedRanges;
6149
6144
  }
6150
6145
 
6151
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6146
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6147
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6148
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6149
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6150
+ return UNDEFINED_VALUE;
6151
+ }
6152
6152
  const crc32 = getUint32$1(dataDescriptorView, offset);
6153
6153
  let compressedSize;
6154
6154
  let uncompressedSize;
6155
- if (extraFieldZip64) {
6156
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6157
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6158
- } else {
6159
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6160
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6155
+ try {
6156
+ if (zip64) {
6157
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6158
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6159
+ } else {
6160
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6161
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6162
+ }
6163
+ } catch {
6164
+ return UNDEFINED_VALUE;
6161
6165
  }
6162
- return { crc32, compressedSize, uncompressedSize };
6166
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6167
+ }
6168
+
6169
+ function getDataDescriptorLength(zip64, signature) {
6170
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6163
6171
  }
6164
6172
 
6165
6173
  function getDiskOffset$1(reader, diskNumber) {
@@ -9080,7 +9088,7 @@ function formatSupported(StreamClass, format) {
9080
9088
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9081
9089
  */
9082
9090
 
9083
- const VERSION = "2.18.0";
9091
+ const VERSION = "2.18.1";
9084
9092
 
9085
9093
  /*
9086
9094
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.