@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/dist/zip.js CHANGED
@@ -6013,32 +6013,19 @@
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;
6036
- }
6037
- }
6038
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6039
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6040
- localDataDescriptor.signature = signature;
6019
+ const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
6020
+ .map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
6021
+ .filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
6022
+ const localDataDescriptor = candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
6023
+ readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
6024
+ if (localDataDescriptor) {
6041
6025
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6026
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6027
+ } else {
6028
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6042
6029
  }
6043
6030
  }
6044
6031
  const range = {
@@ -6103,18 +6090,31 @@
6103
6090
  return mergedRanges;
6104
6091
  }
6105
6092
 
6106
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6093
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6094
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6095
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6096
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6097
+ return UNDEFINED_VALUE;
6098
+ }
6107
6099
  const crc32 = getUint32$1(dataDescriptorView, offset);
6108
6100
  let compressedSize;
6109
6101
  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);
6102
+ try {
6103
+ if (zip64) {
6104
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6105
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6106
+ } else {
6107
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6108
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6109
+ }
6110
+ } catch {
6111
+ return UNDEFINED_VALUE;
6116
6112
  }
6117
- return { crc32, compressedSize, uncompressedSize };
6113
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6114
+ }
6115
+
6116
+ function getDataDescriptorLength(zip64, signature) {
6117
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6118
6118
  }
6119
6119
 
6120
6120
  function getDiskOffset$1(reader, diskNumber) {
@@ -8937,7 +8937,7 @@
8937
8937
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8938
8938
  */
8939
8939
 
8940
- const VERSION = "2.18.0";
8940
+ const VERSION = "2.18.2";
8941
8941
 
8942
8942
  /*
8943
8943
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.