@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/index.cjs CHANGED
@@ -6027,32 +6027,27 @@ async function detectOverlappingEntry({
6027
6027
  }) {
6028
6028
  let dataDescriptorLength = 0;
6029
6029
  if (dataDescriptor) {
6030
- if (extraFieldZip64) {
6031
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH;
6032
- } else {
6033
- dataDescriptorLength = DATA_DESCRIPTOR_RECORD_LENGTH;
6034
- }
6035
- }
6036
- if (dataDescriptorLength) {
6037
- const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6030
+ const zip64 = Boolean(extraFieldZip64);
6031
+ const dataDescriptorArray = await readUint8Array(reader, dataOffset + compressedSize, DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH);
6038
6032
  const dataDescriptorView = getDataView(dataDescriptorArray);
6039
- let signature = dataDescriptorArray.length == dataDescriptorLength + DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH &&
6040
- getUint32$1(dataDescriptorView, 0) == DATA_DESCRIPTOR_RECORD_SIGNATURE;
6041
- if (signature) {
6042
- const signedDataDescriptor = readDataDescriptor(dataDescriptorView, DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH, extraFieldZip64);
6043
- const matchCrc32 = (fileEntry.encrypted && !fileEntry.zipCrypto) || signedDataDescriptor.crc32 == crc32;
6044
- if (matchCrc32 &&
6045
- signedDataDescriptor.compressedSize == compressedSize &&
6046
- signedDataDescriptor.uncompressedSize == uncompressedSize) {
6047
- dataDescriptorLength += DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH;
6048
- } else {
6049
- signature = false;
6033
+ const ignoreCrc32 = fileEntry.encrypted && !fileEntry.zipCrypto;
6034
+ let localDataDescriptor;
6035
+ for (const [zip64Layout, signature] of [[zip64, true], [zip64, false], [!zip64, true], [!zip64, false]]) {
6036
+ const candidate = readDataDescriptor(dataDescriptorView, zip64Layout, signature);
6037
+ if (candidate && (ignoreCrc32 || candidate.crc32 == crc32) &&
6038
+ candidate.compressedSize == compressedSize && candidate.uncompressedSize == uncompressedSize) {
6039
+ localDataDescriptor = candidate;
6040
+ break;
6050
6041
  }
6051
6042
  }
6052
- if (dataDescriptorArray.length >= dataDescriptorLength) {
6053
- const localDataDescriptor = readDataDescriptor(dataDescriptorView, signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0, extraFieldZip64);
6054
- localDataDescriptor.signature = signature;
6043
+ if (!localDataDescriptor) {
6044
+ localDataDescriptor = readDataDescriptor(dataDescriptorView, zip64, false);
6045
+ }
6046
+ if (localDataDescriptor) {
6055
6047
  fileEntry.localDirectory.dataDescriptor = localDataDescriptor;
6048
+ dataDescriptorLength = getDataDescriptorLength(localDataDescriptor.zip64, localDataDescriptor.signature);
6049
+ } else {
6050
+ dataDescriptorLength = getDataDescriptorLength(zip64, false);
6056
6051
  }
6057
6052
  }
6058
6053
  const range = {
@@ -6117,18 +6112,31 @@ function mergeRanges(sortedRanges, pendingRanges) {
6117
6112
  return mergedRanges;
6118
6113
  }
6119
6114
 
6120
- function readDataDescriptor(dataDescriptorView, offset, extraFieldZip64) {
6115
+ function readDataDescriptor(dataDescriptorView, zip64, signature) {
6116
+ const offset = signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0;
6117
+ if (dataDescriptorView.byteLength < getDataDescriptorLength(zip64, signature) ||
6118
+ (signature && getUint32$1(dataDescriptorView, 0) != DATA_DESCRIPTOR_RECORD_SIGNATURE)) {
6119
+ return UNDEFINED_VALUE;
6120
+ }
6121
6121
  const crc32 = getUint32$1(dataDescriptorView, offset);
6122
6122
  let compressedSize;
6123
6123
  let uncompressedSize;
6124
- if (extraFieldZip64) {
6125
- compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6126
- uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6127
- } else {
6128
- compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6129
- uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6124
+ try {
6125
+ if (zip64) {
6126
+ compressedSize = getBigUint64(dataDescriptorView, offset + 4);
6127
+ uncompressedSize = getBigUint64(dataDescriptorView, offset + 12);
6128
+ } else {
6129
+ compressedSize = getUint32$1(dataDescriptorView, offset + 4);
6130
+ uncompressedSize = getUint32$1(dataDescriptorView, offset + 8);
6131
+ }
6132
+ } catch {
6133
+ return UNDEFINED_VALUE;
6130
6134
  }
6131
- return { crc32, compressedSize, uncompressedSize };
6135
+ return { signature, zip64, crc32, compressedSize, uncompressedSize };
6136
+ }
6137
+
6138
+ function getDataDescriptorLength(zip64, signature) {
6139
+ return (zip64 ? DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH : DATA_DESCRIPTOR_RECORD_LENGTH) + (signature ? DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH : 0);
6132
6140
  }
6133
6141
 
6134
6142
  function getDiskOffset$1(reader, diskNumber) {
@@ -9049,7 +9057,7 @@ function formatSupported(StreamClass, format) {
9049
9057
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9050
9058
  */
9051
9059
 
9052
- const VERSION = "2.18.0";
9060
+ const VERSION = "2.18.1";
9053
9061
 
9054
9062
  /*
9055
9063
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.
package/index.d.cts CHANGED
@@ -2244,6 +2244,18 @@ export interface LocalDataDescriptor {
2244
2244
  * read as starting at the first byte.
2245
2245
  */
2246
2246
  signature: boolean;
2247
+ /**
2248
+ * `true` if the sizes are stored as 8-byte values.
2249
+ *
2250
+ * Neither record tells the width reliably: the local file header is written before a streaming writer knows the
2251
+ * sizes, and the Zip64 extra field of the central directory record, written last, describes that record, not the
2252
+ * descriptor, so e.g. an entry placed past 4 GB can carry a Zip64 extra field in its central directory record for
2253
+ * its offset alone and a descriptor with 4-byte sizes. The record is therefore read with the layout, among the two
2254
+ * widths with and without the signature, whose values agree with the central directory; when none does, the width
2255
+ * announced by the Zip64 extra field of the local file header or of the central directory record is used, without
2256
+ * the signature.
2257
+ */
2258
+ zip64: boolean;
2247
2259
  /**
2248
2260
  * The CRC-32 checksum stored in the record, which is allowed to differ from {@link EntryMetaData#crc32}.
2249
2261
  */
package/index.d.ts CHANGED
@@ -2244,6 +2244,18 @@ export interface LocalDataDescriptor {
2244
2244
  * read as starting at the first byte.
2245
2245
  */
2246
2246
  signature: boolean;
2247
+ /**
2248
+ * `true` if the sizes are stored as 8-byte values.
2249
+ *
2250
+ * Neither record tells the width reliably: the local file header is written before a streaming writer knows the
2251
+ * sizes, and the Zip64 extra field of the central directory record, written last, describes that record, not the
2252
+ * descriptor, so e.g. an entry placed past 4 GB can carry a Zip64 extra field in its central directory record for
2253
+ * its offset alone and a descriptor with 4-byte sizes. The record is therefore read with the layout, among the two
2254
+ * widths with and without the signature, whose values agree with the central directory; when none does, the width
2255
+ * announced by the Zip64 extra field of the local file header or of the central directory record is used, without
2256
+ * the signature.
2257
+ */
2258
+ zip64: boolean;
2247
2259
  /**
2248
2260
  * The CRC-32 checksum stored in the record, which is allowed to differ from {@link EntryMetaData#crc32}.
2249
2261
  */