@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.
@@ -4709,6 +4709,7 @@
4709
4709
  const ERR_INVALID_STRICTNESS = "Invalid strictness (must be 'strict', 'balanced' or 'tolerant')";
4710
4710
  const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
4711
4711
  const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
4712
+ const ERR_UNSUPPORTED_UINT64 = "64-bit value exceeds Number.MAX_SAFE_INTEGER";
4712
4713
  const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
4713
4714
  const CHARSET_UTF8 = "utf-8";
4714
4715
  const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
@@ -4731,6 +4732,7 @@
4731
4732
  bytes: 8
4732
4733
  }
4733
4734
  };
4735
+ const MAX_SAFE_UINT64 = BigInt(Number.MAX_SAFE_INTEGER);
4734
4736
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
4735
4737
  const MAX_DEFLATE_EXPANSION_RATIO = 1032;
4736
4738
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
@@ -4826,7 +4828,7 @@
4826
4828
  zip64EndOfDirectoryVersion2 = getBigUint64(endOfDirectoryView, 4) > ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12;
4827
4829
  if (zip64EndOfDirectoryVersion2) {
4828
4830
  const extensibleDataLength = Math.min(
4829
- Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4831
+ getBigUint64(endOfDirectoryView, 4) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4830
4832
  reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4831
4833
  if (extensibleDataLength > 0) {
4832
4834
  zip64EndOfDirectoryLength += extensibleDataLength;
@@ -5407,8 +5409,8 @@
5407
5409
  const hashDataLength = getUint16$1(extensibleDataView, 26);
5408
5410
  Object.assign(directoryEncryptionInfo, {
5409
5411
  compressionMethod: getUint16$1(extensibleDataView, 0),
5410
- compressedSize: Number(getBigUint64(extensibleDataView, 2)),
5411
- uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
5412
+ compressedSize: getBigUint64(extensibleDataView, 2),
5413
+ uncompressedSize: getBigUint64(extensibleDataView, 10),
5412
5414
  encryptionAlgorithm: getUint16$1(extensibleDataView, 18),
5413
5415
  bitLength: getUint16$1(extensibleDataView, 20),
5414
5416
  flags: getUint16$1(extensibleDataView, 22),
@@ -6043,7 +6045,11 @@
6043
6045
  }
6044
6046
 
6045
6047
  function getBigUint64(view, offset) {
6046
- return Number(view.getBigUint64(offset, true));
6048
+ const value = view.getBigUint64(offset, true);
6049
+ if (value > MAX_SAFE_UINT64) {
6050
+ throw new Error(ERR_UNSUPPORTED_UINT64);
6051
+ }
6052
+ return Number(value);
6047
6053
  }
6048
6054
 
6049
6055
  var zipReader = /*#__PURE__*/Object.freeze({
@@ -6072,6 +6078,7 @@
6072
6078
  ERR_UNSAFE_FILENAME: ERR_UNSAFE_FILENAME,
6073
6079
  ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION$1,
6074
6080
  ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
6081
+ ERR_UNSUPPORTED_UINT64: ERR_UNSUPPORTED_UINT64,
6075
6082
  ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
6076
6083
  ZipReader: ZipReader,
6077
6084
  ZipReaderStream: ZipReaderStream
@@ -6212,7 +6219,7 @@
6212
6219
  encrypted,
6213
6220
  uncompressedSize,
6214
6221
  compressedSize,
6215
- zip64
6222
+ extraFieldZip64
6216
6223
  } = entry;
6217
6224
  let {
6218
6225
  compressionMethod,
@@ -6229,13 +6236,13 @@
6229
6236
  rawExtraFieldExtendedTimestamp = rawExtraFieldExtendedTimestamp || EMPTY_UINT8_ARRAY;
6230
6237
  rawExtraFieldNTFS = rawExtraFieldNTFS || EMPTY_UINT8_ARRAY;
6231
6238
  rawExtraFieldUnix = rawExtraFieldUnix || EMPTY_UINT8_ARRAY;
6232
- rawExtraField = rawExtraField || EMPTY_UINT8_ARRAY;
6239
+ rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
6233
6240
  if (entry.extraFieldAES) {
6234
6241
  compressionMethod = COMPRESSION_METHOD_AES;
6235
6242
  }
6236
6243
  const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
6237
- const zip64UncompressedSize = zip64 && uncompressedSize >= MAX_32_BITS;
6238
- const zip64CompressedSize = zip64 && compressedSize >= MAX_32_BITS;
6244
+ const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
6245
+ const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
6239
6246
  const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
6240
6247
  const {
6241
6248
  headerArray,
@@ -6791,6 +6798,10 @@
6791
6798
  maximumCompressedSize = contentSize === UNDEFINED_VALUE ? getMaximumCompressedSize(uncompressedSize) + encryptionOverhead : contentSize;
6792
6799
  }
6793
6800
  }
6801
+ const emptyEntry = !encryptedEntry && (!hasContent || (contentSize === 0 && !passThrough)) && !isCompressed(compressionMethod, level);
6802
+ if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
6803
+ dataDescriptor = false;
6804
+ }
6794
6805
  const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
6795
6806
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
6796
6807
  if (zip64UncompressedSize || zip64CompressedSize) {
@@ -6805,6 +6816,7 @@
6805
6816
  maximumCompressedSize,
6806
6817
  resolvedOptions: {
6807
6818
  dataDescriptor,
6819
+ emptyEntry,
6808
6820
  zip64,
6809
6821
  zip64UncompressedSize,
6810
6822
  zip64CompressedSize,
@@ -6824,6 +6836,7 @@
6824
6836
  const {
6825
6837
  keepOrder,
6826
6838
  dataDescriptor,
6839
+ emptyEntry,
6827
6840
  signal
6828
6841
  } = options;
6829
6842
  const {
@@ -6848,7 +6861,7 @@
6848
6861
  lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
6849
6862
  requestLockCurrentFileEntry();
6850
6863
  }
6851
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
6864
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
6852
6865
  bufferedWrite = true;
6853
6866
  zipWriter.bufferedWrites++;
6854
6867
  if (options.createTempStream) {
@@ -7270,8 +7283,8 @@
7270
7283
  try {
7271
7284
  const { uid, gid, unixExtraFieldType } = options;
7272
7285
  if (unixExtraFieldType == INFOZIP_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
7273
- const uidBytes = packUnixId(uid);
7274
- const gidBytes = packUnixId(gid);
7286
+ const uidBytes = packUnixId(uid === UNDEFINED_VALUE ? 0 : uid);
7287
+ const gidBytes = packUnixId(gid === UNDEFINED_VALUE ? 0 : gid);
7275
7288
  const payloadLength = 3 + uidBytes.length + gidBytes.length;
7276
7289
  const extraFieldUnix = createRecordWriter(4 + payloadLength);
7277
7290
  extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_INFOZIP);
@@ -7402,18 +7415,14 @@
7402
7415
  }
7403
7416
 
7404
7417
  function packUnixId(id) {
7405
- if (id === UNDEFINED_VALUE) {
7406
- return EMPTY_UINT8_ARRAY;
7407
- } else {
7408
- const dataArray = new Uint8Array(4);
7409
- const dataView = getDataView(dataArray);
7410
- dataView.setUint32(0, id, true);
7411
- let length = 4;
7412
- while (length > 1 && dataArray[length - 1] === 0) {
7413
- length--;
7414
- }
7415
- return dataArray.subarray(0, length);
7418
+ const dataArray = new Uint8Array(4);
7419
+ const dataView = getDataView(dataArray);
7420
+ dataView.setUint32(0, id, true);
7421
+ let length = 4;
7422
+ while (length > 1 && dataArray[length - 1] === 0) {
7423
+ length--;
7416
7424
  }
7425
+ return dataArray.subarray(0, length);
7417
7426
  }
7418
7427
 
7419
7428
  function normalizeMsdosAttributes(msdosAttributesRaw, msdosAttributes) {
@@ -7832,6 +7841,21 @@
7832
7841
  return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
7833
7842
  }
7834
7843
 
7844
+ function removeExtraFieldZip64(rawExtraField) {
7845
+ const rawExtraFieldView = getDataView(rawExtraField);
7846
+ let offsetExtraField = 0;
7847
+ while (offsetExtraField + 4 <= getLength(rawExtraField)) {
7848
+ const size = 4 + getUint16(rawExtraFieldView, offsetExtraField + 2);
7849
+ if (getUint16(rawExtraFieldView, offsetExtraField) == EXTRAFIELD_TYPE_ZIP64) {
7850
+ return removeExtraFieldZip64(concat(
7851
+ rawExtraField.subarray(0, offsetExtraField),
7852
+ rawExtraField.subarray(Math.min(offsetExtraField + size, getLength(rawExtraField)))));
7853
+ }
7854
+ offsetExtraField += size;
7855
+ }
7856
+ return rawExtraField;
7857
+ }
7858
+
7835
7859
  async function copyZipData(zipWriter, reader, entries, directoryOffset) {
7836
7860
  const { writer } = zipWriter;
7837
7861
  const entryPositions = new Map();
@@ -8671,6 +8695,7 @@
8671
8695
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
8672
8696
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
8673
8697
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
8698
+ exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
8674
8699
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
8675
8700
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;
8676
8701
  exports.ERR_ZIP_NOT_EMPTY = ERR_ZIP_NOT_EMPTY;