@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/index-native.cjs CHANGED
@@ -6019,32 +6019,19 @@ 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;
6042
- }
6043
- }
6044
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6045
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6046
- localDataDescriptor.signature = signature;
6025
+ const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
6026
+ .map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
6027
+ .filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
6028
+ const localDataDescriptor = candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
6029
+ readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
6030
+ if (localDataDescriptor) {
6047
6031
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6032
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6033
+ } else {
6034
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6048
6035
  }
6049
6036
  }
6050
6037
  const range = {
@@ -6109,18 +6096,31 @@ function mergeRanges(sortedRanges, pendingRanges) {
6109
6096
  return mergedRanges;
6110
6097
  }
6111
6098
 
6112
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6099
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6100
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6101
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6102
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6103
+ return UNDEFINED_VALUE;
6104
+ }
6113
6105
  const crc32 = getUint32$1(dataDescriptorView, offset);
6114
6106
  let compressedSize;
6115
6107
  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);
6108
+ try {
6109
+ if (zip64) {
6110
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6111
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6112
+ } else {
6113
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6114
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6115
+ }
6116
+ } catch {
6117
+ return UNDEFINED_VALUE;
6122
6118
  }
6123
- return { crc32, compressedSize, uncompressedSize };
6119
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6120
+ }
6121
+
6122
+ function getDataDescriptorLength(zip64, signature) {
6123
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6124
6124
  }
6125
6125
 
6126
6126
  function getDiskOffset$1(reader, diskNumber) {
@@ -9041,7 +9041,7 @@ function formatSupported(StreamClass, format) {
9041
9041
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9042
9042
  */
9043
9043
 
9044
- const VERSION = "2.18.0";
9044
+ const VERSION = "2.18.2";
9045
9045
 
9046
9046
  /*
9047
9047
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.