@zip.js/zip.js 2.8.56 → 2.8.57

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.js CHANGED
@@ -4713,6 +4713,7 @@
4713
4713
  const ERR_INVALID_STRICTNESS = "Invalid strictness (must be 'strict', 'balanced' or 'tolerant')";
4714
4714
  const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
4715
4715
  const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
4716
+ const ERR_UNSUPPORTED_UINT64 = "64-bit value exceeds Number.MAX_SAFE_INTEGER";
4716
4717
  const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
4717
4718
  const CHARSET_UTF8 = "utf-8";
4718
4719
  const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
@@ -4735,6 +4736,7 @@
4735
4736
  bytes: 8
4736
4737
  }
4737
4738
  };
4739
+ const MAX_SAFE_UINT64 = BigInt(Number.MAX_SAFE_INTEGER);
4738
4740
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
4739
4741
  const MAX_DEFLATE_EXPANSION_RATIO = 1032;
4740
4742
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
@@ -4830,7 +4832,7 @@
4830
4832
  zip64EndOfDirectoryVersion2 = getBigUint64(endOfDirectoryView, 4) > ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12;
4831
4833
  if (zip64EndOfDirectoryVersion2) {
4832
4834
  const extensibleDataLength = Math.min(
4833
- Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4835
+ getBigUint64(endOfDirectoryView, 4) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4834
4836
  reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4835
4837
  if (extensibleDataLength > 0) {
4836
4838
  zip64EndOfDirectoryLength += extensibleDataLength;
@@ -5411,8 +5413,8 @@
5411
5413
  const hashDataLength = getUint16$1(extensibleDataView, 26);
5412
5414
  Object.assign(directoryEncryptionInfo, {
5413
5415
  compressionMethod: getUint16$1(extensibleDataView, 0),
5414
- compressedSize: Number(getBigUint64(extensibleDataView, 2)),
5415
- uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
5416
+ compressedSize: getBigUint64(extensibleDataView, 2),
5417
+ uncompressedSize: getBigUint64(extensibleDataView, 10),
5416
5418
  encryptionAlgorithm: getUint16$1(extensibleDataView, 18),
5417
5419
  bitLength: getUint16$1(extensibleDataView, 20),
5418
5420
  flags: getUint16$1(extensibleDataView, 22),
@@ -6047,7 +6049,11 @@
6047
6049
  }
6048
6050
 
6049
6051
  function getBigUint64(view, offset) {
6050
- return Number(view.getBigUint64(offset, true));
6052
+ const value = view.getBigUint64(offset, true);
6053
+ if (value > MAX_SAFE_UINT64) {
6054
+ throw new Error(ERR_UNSUPPORTED_UINT64);
6055
+ }
6056
+ return Number(value);
6051
6057
  }
6052
6058
 
6053
6059
  var zipReader = /*#__PURE__*/Object.freeze({
@@ -6076,6 +6082,7 @@
6076
6082
  ERR_UNSAFE_FILENAME: ERR_UNSAFE_FILENAME,
6077
6083
  ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION$1,
6078
6084
  ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
6085
+ ERR_UNSUPPORTED_UINT64: ERR_UNSUPPORTED_UINT64,
6079
6086
  ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
6080
6087
  ZipReader: ZipReader,
6081
6088
  ZipReaderStream: ZipReaderStream
@@ -6216,7 +6223,7 @@
6216
6223
  encrypted,
6217
6224
  uncompressedSize,
6218
6225
  compressedSize,
6219
- zip64
6226
+ extraFieldZip64
6220
6227
  } = entry;
6221
6228
  let {
6222
6229
  compressionMethod,
@@ -6233,13 +6240,13 @@
6233
6240
  rawExtraFieldExtendedTimestamp = rawExtraFieldExtendedTimestamp || EMPTY_UINT8_ARRAY;
6234
6241
  rawExtraFieldNTFS = rawExtraFieldNTFS || EMPTY_UINT8_ARRAY;
6235
6242
  rawExtraFieldUnix = rawExtraFieldUnix || EMPTY_UINT8_ARRAY;
6236
- rawExtraField = rawExtraField || EMPTY_UINT8_ARRAY;
6243
+ rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
6237
6244
  if (entry.extraFieldAES) {
6238
6245
  compressionMethod = COMPRESSION_METHOD_AES;
6239
6246
  }
6240
6247
  const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
6241
- const zip64UncompressedSize = zip64 && uncompressedSize >= MAX_32_BITS;
6242
- const zip64CompressedSize = zip64 && compressedSize >= MAX_32_BITS;
6248
+ const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
6249
+ const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
6243
6250
  const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
6244
6251
  const {
6245
6252
  headerArray,
@@ -6795,6 +6802,10 @@
6795
6802
  maximumCompressedSize = contentSize === UNDEFINED_VALUE ? getMaximumCompressedSize(uncompressedSize) + encryptionOverhead : contentSize;
6796
6803
  }
6797
6804
  }
6805
+ const emptyEntry = !encryptedEntry && (!hasContent || (contentSize === 0 && !passThrough)) && !isCompressed(compressionMethod, level);
6806
+ if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
6807
+ dataDescriptor = false;
6808
+ }
6798
6809
  const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
6799
6810
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
6800
6811
  if (zip64UncompressedSize || zip64CompressedSize) {
@@ -6809,6 +6820,7 @@
6809
6820
  maximumCompressedSize,
6810
6821
  resolvedOptions: {
6811
6822
  dataDescriptor,
6823
+ emptyEntry,
6812
6824
  zip64,
6813
6825
  zip64UncompressedSize,
6814
6826
  zip64CompressedSize,
@@ -6828,6 +6840,7 @@
6828
6840
  const {
6829
6841
  keepOrder,
6830
6842
  dataDescriptor,
6843
+ emptyEntry,
6831
6844
  signal
6832
6845
  } = options;
6833
6846
  const {
@@ -6852,7 +6865,7 @@
6852
6865
  lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
6853
6866
  requestLockCurrentFileEntry();
6854
6867
  }
6855
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
6868
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
6856
6869
  bufferedWrite = true;
6857
6870
  zipWriter.bufferedWrites++;
6858
6871
  if (options.createTempStream) {
@@ -7274,8 +7287,8 @@
7274
7287
  try {
7275
7288
  const { uid, gid, unixExtraFieldType } = options;
7276
7289
  if (unixExtraFieldType == INFOZIP_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
7277
- const uidBytes = packUnixId(uid);
7278
- const gidBytes = packUnixId(gid);
7290
+ const uidBytes = packUnixId(uid === UNDEFINED_VALUE ? 0 : uid);
7291
+ const gidBytes = packUnixId(gid === UNDEFINED_VALUE ? 0 : gid);
7279
7292
  const payloadLength = 3 + uidBytes.length + gidBytes.length;
7280
7293
  const extraFieldUnix = createRecordWriter(4 + payloadLength);
7281
7294
  extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_INFOZIP);
@@ -7406,18 +7419,14 @@
7406
7419
  }
7407
7420
 
7408
7421
  function packUnixId(id) {
7409
- if (id === UNDEFINED_VALUE) {
7410
- return EMPTY_UINT8_ARRAY;
7411
- } else {
7412
- const dataArray = new Uint8Array(4);
7413
- const dataView = getDataView(dataArray);
7414
- dataView.setUint32(0, id, true);
7415
- let length = 4;
7416
- while (length > 1 && dataArray[length - 1] === 0) {
7417
- length--;
7418
- }
7419
- return dataArray.subarray(0, length);
7422
+ const dataArray = new Uint8Array(4);
7423
+ const dataView = getDataView(dataArray);
7424
+ dataView.setUint32(0, id, true);
7425
+ let length = 4;
7426
+ while (length > 1 && dataArray[length - 1] === 0) {
7427
+ length--;
7420
7428
  }
7429
+ return dataArray.subarray(0, length);
7421
7430
  }
7422
7431
 
7423
7432
  function normalizeMsdosAttributes(msdosAttributesRaw, msdosAttributes) {
@@ -7836,6 +7845,21 @@
7836
7845
  return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
7837
7846
  }
7838
7847
 
7848
+ function removeExtraFieldZip64(rawExtraField) {
7849
+ const rawExtraFieldView = getDataView(rawExtraField);
7850
+ let offsetExtraField = 0;
7851
+ while (offsetExtraField + 4 <= getLength(rawExtraField)) {
7852
+ const size = 4 + getUint16(rawExtraFieldView, offsetExtraField + 2);
7853
+ if (getUint16(rawExtraFieldView, offsetExtraField) == EXTRAFIELD_TYPE_ZIP64) {
7854
+ return removeExtraFieldZip64(concat(
7855
+ rawExtraField.subarray(0, offsetExtraField),
7856
+ rawExtraField.subarray(Math.min(offsetExtraField + size, getLength(rawExtraField)))));
7857
+ }
7858
+ offsetExtraField += size;
7859
+ }
7860
+ return rawExtraField;
7861
+ }
7862
+
7839
7863
  async function copyZipData(zipWriter, reader, entries, directoryOffset) {
7840
7864
  const { writer } = zipWriter;
7841
7865
  const entryPositions = new Map();
@@ -9078,6 +9102,7 @@
9078
9102
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
9079
9103
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
9080
9104
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
9105
+ exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
9081
9106
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
9082
9107
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;
9083
9108
  exports.ERR_ZIP_NOT_EMPTY = ERR_ZIP_NOT_EMPTY;