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