@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.
@@ -6005,32 +6005,19 @@
6005
6005
  }) {
6006
6006
  let dataDescriptorLength = 0;
6007
6007
  if (dataDescriptor) {
6008
- if (extraFieldZip64) {
6009
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6010
- } else {
6011
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6012
- }
6013
- }
6014
- if (dataDescriptorLength) {
6015
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6008
+ const zip64 = Boolean(extraFieldZip64);
6009
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6016
6010
  const dataDescriptorView = getDataView(dataDescriptorArray);
6017
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6018
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6019
- if (signature) {
6020
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6021
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6022
- if (matchCrc32 &&
6023
- signedDataDescriptor.compressedSize == compressedSize &&
6024
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6025
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6026
- } else {
6027
- signature = false;
6028
- }
6029
- }
6030
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6031
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6032
- localDataDescriptor.signature = signature;
6011
+ const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
6012
+ .map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
6013
+ .filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
6014
+ const localDataDescriptor = candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
6015
+ readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
6016
+ if (localDataDescriptor) {
6033
6017
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6018
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6019
+ } else {
6020
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6034
6021
  }
6035
6022
  }
6036
6023
  const range = {
@@ -6095,18 +6082,31 @@
6095
6082
  return mergedRanges;
6096
6083
  }
6097
6084
 
6098
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6085
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6086
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6087
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6088
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6089
+ return UNDEFINED_VALUE;
6090
+ }
6099
6091
  const crc32 = getUint32$1(dataDescriptorView, offset);
6100
6092
  let compressedSize;
6101
6093
  let uncompressedSize;
6102
- if (extraFieldZip64) {
6103
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6104
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6105
- } else {
6106
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6107
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6094
+ try {
6095
+ if (zip64) {
6096
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6097
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6098
+ } else {
6099
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6100
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6101
+ }
6102
+ } catch {
6103
+ return UNDEFINED_VALUE;
6108
6104
  }
6109
- return { crc32, compressedSize, uncompressedSize };
6105
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6106
+ }
6107
+
6108
+ function getDataDescriptorLength(zip64, signature) {
6109
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6110
6110
  }
6111
6111
 
6112
6112
  function getDiskOffset$1(reader, diskNumber) {
@@ -8929,7 +8929,7 @@
8929
8929
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8930
8930
  */
8931
8931
 
8932
- const VERSION = "2.18.0";
8932
+ const VERSION = "2.18.2";
8933
8933
 
8934
8934
  /*
8935
8935
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.