@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/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.2",
4
4
  "exports": {
5
5
  ".": "./index.js",
6
6
  "./external": "./lib/zip-fs-external.js",
@@ -6038,32 +6038,19 @@ 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;
6061
- }
6062
- }
6063
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6064
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6065
- localDataDescriptor.signature = signature;
6044
+ const candidates = [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]
6045
+ .map(([zip64Layout, signature]) => readDataDescriptor(dataDescriptorView, zip64Layout, signature))
6046
+ .filter(candidate => candidate && candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize);
6047
+ const localDataDescriptor = candidates.find(candidate => candidate.crc32 == crc32) || candidates[0] ||
6048
+ readDataDescriptor(dataDescriptorView, zip64, true) || readDataDescriptor(dataDescriptorView, zip64, false);
6049
+ if (localDataDescriptor) {
6066
6050
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6051
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6052
+ } else {
6053
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6067
6054
  }
6068
6055
  }
6069
6056
  const range = {
@@ -6128,18 +6115,31 @@ function mergeRanges(sortedRanges, pendingRanges) {
6128
6115
  return mergedRanges;
6129
6116
  }
6130
6117
 
6131
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6118
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6119
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6120
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6121
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6122
+ return UNDEFINED_VALUE;
6123
+ }
6132
6124
  const crc32 = getUint32$1(dataDescriptorView, offset);
6133
6125
  let compressedSize;
6134
6126
  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);
6127
+ try {
6128
+ if (zip64) {
6129
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6130
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6131
+ } else {
6132
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6133
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6134
+ }
6135
+ } catch {
6136
+ return UNDEFINED_VALUE;
6141
6137
  }
6142
- return { crc32, compressedSize, uncompressedSize };
6138
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6139
+ }
6140
+
6141
+ function getDataDescriptorLength(zip64, signature) {
6142
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6143
6143
  }
6144
6144
 
6145
6145
  function getDiskOffset$1(reader, diskNumber) {
@@ -8962,7 +8962,7 @@ function formatSupported(StreamClass, format) {
8962
8962
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8963
8963
  */
8964
8964
 
8965
- const VERSION = "2.18.0";
8965
+ const VERSION = "2.18.2";
8966
8966
 
8967
8967
  /*
8968
8968
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.