@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-core.js CHANGED
@@ -4707,6 +4707,7 @@
4707
4707
  const ERR_INVALID_STRICTNESS = "Invalid strictness (must be 'strict', 'balanced' or 'tolerant')";
4708
4708
  const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
4709
4709
  const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
4710
+ const ERR_UNSUPPORTED_UINT64 = "64-bit value exceeds Number.MAX_SAFE_INTEGER";
4710
4711
  const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
4711
4712
  const CHARSET_UTF8 = "utf-8";
4712
4713
  const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
@@ -4729,6 +4730,7 @@
4729
4730
  bytes: 8
4730
4731
  }
4731
4732
  };
4733
+ const MAX_SAFE_UINT64 = BigInt(Number.MAX_SAFE_INTEGER);
4732
4734
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
4733
4735
  const MAX_DEFLATE_EXPANSION_RATIO = 1032;
4734
4736
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
@@ -4824,7 +4826,7 @@
4824
4826
  zip64EndOfDirectoryVersion2 = getBigUint64(endOfDirectoryView, 4) > ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12;
4825
4827
  if (zip64EndOfDirectoryVersion2) {
4826
4828
  const extensibleDataLength = Math.min(
4827
- Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4829
+ getBigUint64(endOfDirectoryView, 4) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4828
4830
  reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4829
4831
  if (extensibleDataLength > 0) {
4830
4832
  zip64EndOfDirectoryLength += extensibleDataLength;
@@ -5405,8 +5407,8 @@
5405
5407
  const hashDataLength = getUint16$1(extensibleDataView, 26);
5406
5408
  Object.assign(directoryEncryptionInfo, {
5407
5409
  compressionMethod: getUint16$1(extensibleDataView, 0),
5408
- compressedSize: Number(getBigUint64(extensibleDataView, 2)),
5409
- uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
5410
+ compressedSize: getBigUint64(extensibleDataView, 2),
5411
+ uncompressedSize: getBigUint64(extensibleDataView, 10),
5410
5412
  encryptionAlgorithm: getUint16$1(extensibleDataView, 18),
5411
5413
  bitLength: getUint16$1(extensibleDataView, 20),
5412
5414
  flags: getUint16$1(extensibleDataView, 22),
@@ -6041,7 +6043,11 @@
6041
6043
  }
6042
6044
 
6043
6045
  function getBigUint64(view, offset) {
6044
- return Number(view.getBigUint64(offset, true));
6046
+ const value = view.getBigUint64(offset, true);
6047
+ if (value > MAX_SAFE_UINT64) {
6048
+ throw new Error(ERR_UNSUPPORTED_UINT64);
6049
+ }
6050
+ return Number(value);
6045
6051
  }
6046
6052
 
6047
6053
  var zipReader = /*#__PURE__*/Object.freeze({
@@ -6070,6 +6076,7 @@
6070
6076
  ERR_UNSAFE_FILENAME: ERR_UNSAFE_FILENAME,
6071
6077
  ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION$1,
6072
6078
  ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
6079
+ ERR_UNSUPPORTED_UINT64: ERR_UNSUPPORTED_UINT64,
6073
6080
  ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
6074
6081
  ZipReader: ZipReader,
6075
6082
  ZipReaderStream: ZipReaderStream
@@ -6210,7 +6217,7 @@
6210
6217
  encrypted,
6211
6218
  uncompressedSize,
6212
6219
  compressedSize,
6213
- zip64
6220
+ extraFieldZip64
6214
6221
  } = entry;
6215
6222
  let {
6216
6223
  compressionMethod,
@@ -6227,13 +6234,13 @@
6227
6234
  rawExtraFieldExtendedTimestamp = rawExtraFieldExtendedTimestamp || EMPTY_UINT8_ARRAY;
6228
6235
  rawExtraFieldNTFS = rawExtraFieldNTFS || EMPTY_UINT8_ARRAY;
6229
6236
  rawExtraFieldUnix = rawExtraFieldUnix || EMPTY_UINT8_ARRAY;
6230
- rawExtraField = rawExtraField || EMPTY_UINT8_ARRAY;
6237
+ rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
6231
6238
  if (entry.extraFieldAES) {
6232
6239
  compressionMethod = COMPRESSION_METHOD_AES;
6233
6240
  }
6234
6241
  const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
6235
- const zip64UncompressedSize = zip64 && uncompressedSize >= MAX_32_BITS;
6236
- const zip64CompressedSize = zip64 && compressedSize >= MAX_32_BITS;
6242
+ const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
6243
+ const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
6237
6244
  const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
6238
6245
  const {
6239
6246
  headerArray,
@@ -6789,6 +6796,10 @@
6789
6796
  maximumCompressedSize = contentSize === UNDEFINED_VALUE ? getMaximumCompressedSize(uncompressedSize) + encryptionOverhead : contentSize;
6790
6797
  }
6791
6798
  }
6799
+ const emptyEntry = !encryptedEntry && (!hasContent || (contentSize === 0 && !passThrough)) && !isCompressed(compressionMethod, level);
6800
+ if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
6801
+ dataDescriptor = false;
6802
+ }
6792
6803
  const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
6793
6804
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
6794
6805
  if (zip64UncompressedSize || zip64CompressedSize) {
@@ -6803,6 +6814,7 @@
6803
6814
  maximumCompressedSize,
6804
6815
  resolvedOptions: {
6805
6816
  dataDescriptor,
6817
+ emptyEntry,
6806
6818
  zip64,
6807
6819
  zip64UncompressedSize,
6808
6820
  zip64CompressedSize,
@@ -6822,6 +6834,7 @@
6822
6834
  const {
6823
6835
  keepOrder,
6824
6836
  dataDescriptor,
6837
+ emptyEntry,
6825
6838
  signal
6826
6839
  } = options;
6827
6840
  const {
@@ -6846,7 +6859,7 @@
6846
6859
  lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
6847
6860
  requestLockCurrentFileEntry();
6848
6861
  }
6849
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
6862
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
6850
6863
  bufferedWrite = true;
6851
6864
  zipWriter.bufferedWrites++;
6852
6865
  if (options.createTempStream) {
@@ -7268,8 +7281,8 @@
7268
7281
  try {
7269
7282
  const { uid, gid, unixExtraFieldType } = options;
7270
7283
  if (unixExtraFieldType == INFOZIP_EXTRA_FIELD_TYPE && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
7271
- const uidBytes = packUnixId(uid);
7272
- const gidBytes = packUnixId(gid);
7284
+ const uidBytes = packUnixId(uid === UNDEFINED_VALUE ? 0 : uid);
7285
+ const gidBytes = packUnixId(gid === UNDEFINED_VALUE ? 0 : gid);
7273
7286
  const payloadLength = 3 + uidBytes.length + gidBytes.length;
7274
7287
  const extraFieldUnix = createRecordWriter(4 + payloadLength);
7275
7288
  extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_INFOZIP);
@@ -7400,18 +7413,14 @@
7400
7413
  }
7401
7414
 
7402
7415
  function packUnixId(id) {
7403
- if (id === UNDEFINED_VALUE) {
7404
- return EMPTY_UINT8_ARRAY;
7405
- } else {
7406
- const dataArray = new Uint8Array(4);
7407
- const dataView = getDataView(dataArray);
7408
- dataView.setUint32(0, id, true);
7409
- let length = 4;
7410
- while (length > 1 && dataArray[length - 1] === 0) {
7411
- length--;
7412
- }
7413
- return dataArray.subarray(0, length);
7416
+ const dataArray = new Uint8Array(4);
7417
+ const dataView = getDataView(dataArray);
7418
+ dataView.setUint32(0, id, true);
7419
+ let length = 4;
7420
+ while (length > 1 && dataArray[length - 1] === 0) {
7421
+ length--;
7414
7422
  }
7423
+ return dataArray.subarray(0, length);
7415
7424
  }
7416
7425
 
7417
7426
  function normalizeMsdosAttributes(msdosAttributesRaw, msdosAttributes) {
@@ -7830,6 +7839,21 @@
7830
7839
  return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
7831
7840
  }
7832
7841
 
7842
+ function removeExtraFieldZip64(rawExtraField) {
7843
+ const rawExtraFieldView = getDataView(rawExtraField);
7844
+ let offsetExtraField = 0;
7845
+ while (offsetExtraField + 4 <= getLength(rawExtraField)) {
7846
+ const size = 4 + getUint16(rawExtraFieldView, offsetExtraField + 2);
7847
+ if (getUint16(rawExtraFieldView, offsetExtraField) == EXTRAFIELD_TYPE_ZIP64) {
7848
+ return removeExtraFieldZip64(concat(
7849
+ rawExtraField.subarray(0, offsetExtraField),
7850
+ rawExtraField.subarray(Math.min(offsetExtraField + size, getLength(rawExtraField)))));
7851
+ }
7852
+ offsetExtraField += size;
7853
+ }
7854
+ return rawExtraField;
7855
+ }
7856
+
7833
7857
  async function copyZipData(zipWriter, reader, entries, directoryOffset) {
7834
7858
  const { writer } = zipWriter;
7835
7859
  const entryPositions = new Map();
@@ -8638,6 +8662,7 @@
8638
8662
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
8639
8663
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
8640
8664
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
8665
+ exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
8641
8666
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
8642
8667
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;
8643
8668
  exports.ERR_ZIP_NOT_EMPTY = ERR_ZIP_NOT_EMPTY;