@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/dist/zip.js CHANGED
@@ -6013,32 +6013,27 @@
6013
6013
  }) {
6014
6014
  let dataDescriptorLength = 0;
6015
6015
  if (dataDescriptor) {
6016
- if (extraFieldZip64) {
6017
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6018
- } else {
6019
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6020
- }
6021
- }
6022
- if (dataDescriptorLength) {
6023
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6016
+ const zip64 = Boolean(extraFieldZip64);
6017
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6024
6018
  const dataDescriptorView = getDataView(dataDescriptorArray);
6025
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6026
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6027
- if (signature) {
6028
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6029
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6030
- if (matchCrc32 &&
6031
- signedDataDescriptor.compressedSize == compressedSize &&
6032
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6033
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6034
- } else {
6035
- signature = false;
6019
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
6020
+ let localDataDescriptor;
6021
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
6022
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
6023
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
6024
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
6025
+ localDataDescriptor = candidate;
6026
+ break;
6036
6027
  }
6037
6028
  }
6038
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6039
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6040
- localDataDescriptor.signature = signature;
6029
+ if (!localDataDescriptor) {
6030
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
6031
+ }
6032
+ if (localDataDescriptor) {
6041
6033
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6034
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6035
+ } else {
6036
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6042
6037
  }
6043
6038
  }
6044
6039
  const range = {
@@ -6103,18 +6098,31 @@
6103
6098
  return mergedRanges;
6104
6099
  }
6105
6100
 
6106
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6101
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6102
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6103
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6104
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6105
+ return UNDEFINED_VALUE;
6106
+ }
6107
6107
  const crc32 = getUint32$1(dataDescriptorView, offset);
6108
6108
  let compressedSize;
6109
6109
  let uncompressedSize;
6110
- if (extraFieldZip64) {
6111
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6112
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6113
- } else {
6114
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6115
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6110
+ try {
6111
+ if (zip64) {
6112
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6113
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6114
+ } else {
6115
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6116
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6117
+ }
6118
+ } catch {
6119
+ return UNDEFINED_VALUE;
6116
6120
  }
6117
- return { crc32, compressedSize, uncompressedSize };
6121
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6122
+ }
6123
+
6124
+ function getDataDescriptorLength(zip64, signature) {
6125
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6118
6126
  }
6119
6127
 
6120
6128
  function getDiskOffset$1(reader, diskNumber) {
@@ -8937,7 +8945,7 @@
8937
8945
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8938
8946
  */
8939
8947
 
8940
- const VERSION = "2.18.0";
8948
+ const VERSION = "2.18.1";
8941
8949
 
8942
8950
  /*
8943
8951
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.