@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/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zip-js/zip-js",
3
- "version": "2.18.0",
3
+ "version": "2.18.1",
4
4
  "exports": {
5
5
  ".": "./index.js",
6
6
  "./external": "./lib/zip-fs-external.js",
@@ -6038,32 +6038,27 @@ async function detectOverlappingEntry({
6038
6038
  }) {
6039
6039
  let dataDescriptorLength = 0;
6040
6040
  if (dataDescriptor) {
6041
- if (extraFieldZip64) {
6042
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6043
- } else {
6044
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6045
- }
6046
- }
6047
- if (dataDescriptorLength) {
6048
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6041
+ const zip64 = Boolean(extraFieldZip64);
6042
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6049
6043
  const dataDescriptorView = getDataView(dataDescriptorArray);
6050
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6051
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6052
- if (signature) {
6053
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6054
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6055
- if (matchCrc32 &&
6056
- signedDataDescriptor.compressedSize == compressedSize &&
6057
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6058
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6059
- } else {
6060
- signature = false;
6044
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
6045
+ let localDataDescriptor;
6046
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
6047
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
6048
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
6049
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
6050
+ localDataDescriptor = candidate;
6051
+ break;
6061
6052
  }
6062
6053
  }
6063
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6064
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6065
- localDataDescriptor.signature = signature;
6054
+ if (!localDataDescriptor) {
6055
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
6056
+ }
6057
+ if (localDataDescriptor) {
6066
6058
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6059
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6060
+ } else {
6061
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6067
6062
  }
6068
6063
  }
6069
6064
  const range = {
@@ -6128,18 +6123,31 @@ function mergeRanges(sortedRanges, pendingRanges) {
6128
6123
  return mergedRanges;
6129
6124
  }
6130
6125
 
6131
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6126
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6127
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6128
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6129
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6130
+ return UNDEFINED_VALUE;
6131
+ }
6132
6132
  const crc32 = getUint32$1(dataDescriptorView, offset);
6133
6133
  let compressedSize;
6134
6134
  let uncompressedSize;
6135
- if (extraFieldZip64) {
6136
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6137
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6138
- } else {
6139
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6140
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6135
+ try {
6136
+ if (zip64) {
6137
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6138
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6139
+ } else {
6140
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6141
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6142
+ }
6143
+ } catch {
6144
+ return UNDEFINED_VALUE;
6141
6145
  }
6142
- return { crc32, compressedSize, uncompressedSize };
6146
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6147
+ }
6148
+
6149
+ function getDataDescriptorLength(zip64, signature) {
6150
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6143
6151
  }
6144
6152
 
6145
6153
  function getDiskOffset$1(reader, diskNumber) {
@@ -8962,7 +8970,7 @@ function formatSupported(StreamClass, format) {
8962
8970
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8963
8971
  */
8964
8972
 
8965
- const VERSION = "2.18.0";
8973
+ const VERSION = "2.18.1";
8966
8974
 
8967
8975
  /*
8968
8976
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.