@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.
@@ -6058,32 +6058,19 @@ 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;
6081
- }
6082
- }
6083
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6084
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6085
- localDataDescriptor.signature = signature;
6064
+ const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
6065
+ .map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
6066
+ .filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
6067
+ const localDataDescriptor = candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
6068
+ readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
6069
+ if (localDataDescriptor) {
6086
6070
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6071
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6072
+ } else {
6073
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6087
6074
  }
6088
6075
  }
6089
6076
  const range = {
@@ -6148,18 +6135,31 @@ function mergeRanges(sortedRanges, pendingRanges) {
6148
6135
  return mergedRanges;
6149
6136
  }
6150
6137
 
6151
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6138
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6139
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6140
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6141
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6142
+ return UNDEFINED_VALUE;
6143
+ }
6152
6144
  const crc32 = getUint32$1(dataDescriptorView, offset);
6153
6145
  let compressedSize;
6154
6146
  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);
6147
+ try {
6148
+ if (zip64) {
6149
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6150
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6151
+ } else {
6152
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6153
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6154
+ }
6155
+ } catch {
6156
+ return UNDEFINED_VALUE;
6161
6157
  }
6162
- return { crc32, compressedSize, uncompressedSize };
6158
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6159
+ }
6160
+
6161
+ function getDataDescriptorLength(zip64, signature) {
6162
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6163
6163
  }
6164
6164
 
6165
6165
  function getDiskOffset$1(reader, diskNumber) {
@@ -9080,7 +9080,7 @@ function formatSupported(StreamClass, format) {
9080
9080
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9081
9081
  */
9082
9082
 
9083
- const VERSION = "2.18.0";
9083
+ const VERSION = "2.18.2";
9084
9084
 
9085
9085
  /*
9086
9086
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.