@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/index-native.cjs CHANGED
@@ -6019,32 +6019,27 @@ async function detectOverlappingEntry({
6019
6019
  }) {
6020
6020
  let dataDescriptorLength = 0;
6021
6021
  if (dataDescriptor) {
6022
- if (extraFieldZip64) {
6023
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6024
- } else {
6025
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6026
- }
6027
- }
6028
- if (dataDescriptorLength) {
6029
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6022
+ const zip64 = Boolean(extraFieldZip64);
6023
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6030
6024
  const dataDescriptorView = getDataView(dataDescriptorArray);
6031
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6032
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6033
- if (signature) {
6034
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6035
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6036
- if (matchCrc32 &&
6037
- signedDataDescriptor.compressedSize == compressedSize &&
6038
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6039
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6040
- } else {
6041
- signature = false;
6025
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
6026
+ let localDataDescriptor;
6027
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
6028
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
6029
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
6030
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
6031
+ localDataDescriptor = candidate;
6032
+ break;
6042
6033
  }
6043
6034
  }
6044
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6045
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6046
- localDataDescriptor.signature = signature;
6035
+ if (!localDataDescriptor) {
6036
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
6037
+ }
6038
+ if (localDataDescriptor) {
6047
6039
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6040
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6041
+ } else {
6042
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6048
6043
  }
6049
6044
  }
6050
6045
  const range = {
@@ -6109,18 +6104,31 @@ function mergeRanges(sortedRanges, pendingRanges) {
6109
6104
  return mergedRanges;
6110
6105
  }
6111
6106
 
6112
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6107
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6108
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6109
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6110
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6111
+ return UNDEFINED_VALUE;
6112
+ }
6113
6113
  const crc32 = getUint32$1(dataDescriptorView, offset);
6114
6114
  let compressedSize;
6115
6115
  let uncompressedSize;
6116
- if (extraFieldZip64) {
6117
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6118
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6119
- } else {
6120
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6121
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6116
+ try {
6117
+ if (zip64) {
6118
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6119
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6120
+ } else {
6121
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6122
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6123
+ }
6124
+ } catch {
6125
+ return UNDEFINED_VALUE;
6122
6126
  }
6123
- return { crc32, compressedSize, uncompressedSize };
6127
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6128
+ }
6129
+
6130
+ function getDataDescriptorLength(zip64, signature) {
6131
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6124
6132
  }
6125
6133
 
6126
6134
  function getDiskOffset$1(reader, diskNumber) {
@@ -9041,7 +9049,7 @@ function formatSupported(StreamClass, format) {
9041
9049
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9042
9050
  */
9043
9051
 
9044
- const VERSION = "2.18.0";
9052
+ const VERSION = "2.18.1";
9045
9053
 
9046
9054
  /*
9047
9055
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.