@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/index-native.cjs CHANGED
@@ -4723,6 +4723,7 @@ const ERR_UNSAFE_FILENAME = "Unsafe filename";
4723
4723
  const ERR_INVALID_STRICTNESS = "Invalid strictness (must be 'strict', 'balanced' or 'tolerant')";
4724
4724
  const ERR_INVALID_FILENAME_VALIDATION = "Invalid filenameValidation (must be 'strict', 'balanced' or 'tolerant')";
4725
4725
  const ERR_INVALID_MAX_APPENDED_DATA_SIZE = "Invalid maxAppendedDataSize (must be a number greater than or equal to 0)";
4726
+ const ERR_UNSUPPORTED_UINT64 = "64-bit value exceeds Number.MAX_SAFE_INTEGER";
4726
4727
  const DRIVE_LETTER_REGEXP = /^[a-zA-Z]:/;
4727
4728
  const CHARSET_UTF8 = "utf-8";
4728
4729
  const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
@@ -4745,6 +4746,7 @@ const ZIP64_EXTRACTION = {
4745
4746
  bytes: 8
4746
4747
  }
4747
4748
  };
4749
+ const MAX_SAFE_UINT64 = BigInt(Number.MAX_SAFE_INTEGER);
4748
4750
  const MAX_END_OF_CENTRAL_DIR_PROBES = 64;
4749
4751
  const MAX_DEFLATE_EXPANSION_RATIO = 1032;
4750
4752
  const CENTRAL_DIRECTORY_UNREACHABLE = 0;
@@ -4840,7 +4842,7 @@ class ZipReader {
4840
4842
  zip64EndOfDirectoryVersion2 = getBigUint64(endOfDirectoryView, 4) > ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12;
4841
4843
  if (zip64EndOfDirectoryVersion2) {
4842
4844
  const extensibleDataLength = Math.min(
4843
- Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4845
+ getBigUint64(endOfDirectoryView, 4) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4844
4846
  reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4845
4847
  if (extensibleDataLength > 0) {
4846
4848
  zip64EndOfDirectoryLength += extensibleDataLength;
@@ -5421,8 +5423,8 @@ function getDirectoryEncryptionInfo(rawExtensibleData) {
5421
5423
  const hashDataLength = getUint16$1(extensibleDataView, 26);
5422
5424
  Object.assign(directoryEncryptionInfo, {
5423
5425
  compressionMethod: getUint16$1(extensibleDataView, 0),
5424
- compressedSize: Number(getBigUint64(extensibleDataView, 2)),
5425
- uncompressedSize: Number(getBigUint64(extensibleDataView, 10)),
5426
+ compressedSize: getBigUint64(extensibleDataView, 2),
5427
+ uncompressedSize: getBigUint64(extensibleDataView, 10),
5426
5428
  encryptionAlgorithm: getUint16$1(extensibleDataView, 18),
5427
5429
  bitLength: getUint16$1(extensibleDataView, 20),
5428
5430
  flags: getUint16$1(extensibleDataView, 22),
@@ -6057,7 +6059,11 @@ function getUint32$1(view, offset) {
6057
6059
  }
6058
6060
 
6059
6061
  function getBigUint64(view, offset) {
6060
- return Number(view.getBigUint64(offset, true));
6062
+ const value = view.getBigUint64(offset, true);
6063
+ if (value > MAX_SAFE_UINT64) {
6064
+ throw new Error(ERR_UNSUPPORTED_UINT64);
6065
+ }
6066
+ return Number(value);
6061
6067
  }
6062
6068
 
6063
6069
  var zipReader = /*#__PURE__*/Object.freeze({
@@ -6086,6 +6092,7 @@ var zipReader = /*#__PURE__*/Object.freeze({
6086
6092
  ERR_UNSAFE_FILENAME: ERR_UNSAFE_FILENAME,
6087
6093
  ERR_UNSUPPORTED_COMPRESSION: ERR_UNSUPPORTED_COMPRESSION$1,
6088
6094
  ERR_UNSUPPORTED_ENCRYPTION: ERR_UNSUPPORTED_ENCRYPTION,
6095
+ ERR_UNSUPPORTED_UINT64: ERR_UNSUPPORTED_UINT64,
6089
6096
  ERR_WORKER_STARTUP_TIMEOUT: ERR_WORKER_STARTUP_TIMEOUT,
6090
6097
  ZipReader: ZipReader,
6091
6098
  ZipReaderStream: ZipReaderStream
@@ -6226,7 +6233,7 @@ class ZipWriter {
6226
6233
  encrypted,
6227
6234
  uncompressedSize,
6228
6235
  compressedSize,
6229
- zip64
6236
+ extraFieldZip64
6230
6237
  } = entry;
6231
6238
  let {
6232
6239
  compressionMethod,
@@ -6243,13 +6250,13 @@ class ZipWriter {
6243
6250
  rawExtraFieldExtendedTimestamp = rawExtraFieldExtendedTimestamp || EMPTY_UINT8_ARRAY;
6244
6251
  rawExtraFieldNTFS = rawExtraFieldNTFS || EMPTY_UINT8_ARRAY;
6245
6252
  rawExtraFieldUnix = rawExtraFieldUnix || EMPTY_UINT8_ARRAY;
6246
- rawExtraField = rawExtraField || EMPTY_UINT8_ARRAY;
6253
+ rawExtraField = removeExtraFieldZip64(rawExtraField || EMPTY_UINT8_ARRAY);
6247
6254
  if (entry.extraFieldAES) {
6248
6255
  compressionMethod = COMPRESSION_METHOD_AES;
6249
6256
  }
6250
6257
  const extraFieldLength = getLength(rawExtraFieldZip64, rawExtraFieldAES, rawExtraFieldExtendedTimestamp, rawExtraFieldNTFS, rawExtraFieldUnix, rawExtraField);
6251
- const zip64UncompressedSize = zip64 && uncompressedSize >= MAX_32_BITS;
6252
- const zip64CompressedSize = zip64 && compressedSize >= MAX_32_BITS;
6258
+ const zip64UncompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.uncompressedSize !== UNDEFINED_VALUE;
6259
+ const zip64CompressedSize = Boolean(extraFieldZip64) && extraFieldZip64.compressedSize !== UNDEFINED_VALUE;
6253
6260
  const bitFlagValue = (getBitFlag(level, languageEncodingFlag, dataDescriptor, encrypted, compressionMethod) & ~BITFLAG_LEVEL) | (level << 1);
6254
6261
  const {
6255
6262
  headerArray,
@@ -6805,6 +6812,10 @@ function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options
6805
6812
  maximumCompressedSize = contentSize === UNDEFINED_VALUE ? getMaximumCompressedSize(uncompressedSize) + encryptionOverhead : contentSize;
6806
6813
  }
6807
6814
  }
6815
+ const emptyEntry = !encryptedEntry && (!hasContent || (contentSize === 0 && !passThrough)) && !isCompressed(compressionMethod, level);
6816
+ if (emptyEntry && !zipCrypto && getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR) === UNDEFINED_VALUE) {
6817
+ dataDescriptor = false;
6818
+ }
6808
6819
  const zip64UncompressedSize = zip64Enabled || uncompressedSize >= MAX_32_BITS;
6809
6820
  const zip64CompressedSize = zip64Enabled || maximumCompressedSize >= MAX_32_BITS;
6810
6821
  if (zip64UncompressedSize || zip64CompressedSize) {
@@ -6819,6 +6830,7 @@ function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options
6819
6830
  maximumCompressedSize,
6820
6831
  resolvedOptions: {
6821
6832
  dataDescriptor,
6833
+ emptyEntry,
6822
6834
  zip64,
6823
6835
  zip64UncompressedSize,
6824
6836
  zip64CompressedSize,
@@ -6917,6 +6929,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6917
6929
  const {
6918
6930
  keepOrder,
6919
6931
  dataDescriptor,
6932
+ emptyEntry,
6920
6933
  signal
6921
6934
  } = options;
6922
6935
  const {
@@ -6941,7 +6954,7 @@ async function getFileEntry(zipWriter, name, reader, entryInfo, options) {
6941
6954
  lockPreviousFileEntry = previousFileEntry && previousFileEntry.lockFileEntry;
6942
6955
  requestLockCurrentFileEntry();
6943
6956
  }
6944
- if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || !dataDescriptor) {
6957
+ if (options.bufferedWrite || !keepOrder || zipWriter.writerLocked || zipWriter.bufferedWrites || (!dataDescriptor && !emptyEntry)) {
6945
6958
  bufferedWrite = true;
6946
6959
  zipWriter.bufferedWrites++;
6947
6960
  if (options.createTempStream) {
@@ -7363,8 +7376,8 @@ function getHeaderInfo(options) {
7363
7376
  try {
7364
7377
  const { uid, gid, unixExtraFieldType } = options;
7365
7378
  if (unixExtraFieldType == INFOZIP_EXTRA_FIELD_TYPE$1 && (uid !== UNDEFINED_VALUE || gid !== UNDEFINED_VALUE)) {
7366
- const uidBytes = packUnixId(uid);
7367
- const gidBytes = packUnixId(gid);
7379
+ const uidBytes = packUnixId(uid === UNDEFINED_VALUE ? 0 : uid);
7380
+ const gidBytes = packUnixId(gid === UNDEFINED_VALUE ? 0 : gid);
7368
7381
  const payloadLength = 3 + uidBytes.length + gidBytes.length;
7369
7382
  const extraFieldUnix = createRecordWriter(4 + payloadLength);
7370
7383
  extraFieldUnix.writeUint16(EXTRAFIELD_TYPE_INFOZIP);
@@ -7495,18 +7508,14 @@ function appendExtraFieldUSDZ(entryInfo, zipWriterOffset) {
7495
7508
  }
7496
7509
 
7497
7510
  function packUnixId(id) {
7498
- if (id === UNDEFINED_VALUE) {
7499
- return EMPTY_UINT8_ARRAY;
7500
- } else {
7501
- const dataArray = new Uint8Array(4);
7502
- const dataView = getDataView(dataArray);
7503
- dataView.setUint32(0, id, true);
7504
- let length = 4;
7505
- while (length > 1 && dataArray[length - 1] === 0) {
7506
- length--;
7507
- }
7508
- return dataArray.subarray(0, length);
7511
+ const dataArray = new Uint8Array(4);
7512
+ const dataView = getDataView(dataArray);
7513
+ dataView.setUint32(0, id, true);
7514
+ let length = 4;
7515
+ while (length > 1 && dataArray[length - 1] === 0) {
7516
+ length--;
7509
7517
  }
7518
+ return dataArray.subarray(0, length);
7510
7519
  }
7511
7520
 
7512
7521
  function normalizeMsdosAttributes(msdosAttributesRaw, msdosAttributes) {
@@ -7925,6 +7934,21 @@ async function startsWithSplitZipSignature(reader) {
7925
7934
  return getUint32(getDataView(signatureArray), 0) == SPLIT_ZIP_FILE_SIGNATURE;
7926
7935
  }
7927
7936
 
7937
+ function removeExtraFieldZip64(rawExtraField) {
7938
+ const rawExtraFieldView = getDataView(rawExtraField);
7939
+ let offsetExtraField = 0;
7940
+ while (offsetExtraField + 4 <= getLength(rawExtraField)) {
7941
+ const size = 4 + getUint16(rawExtraFieldView, offsetExtraField + 2);
7942
+ if (getUint16(rawExtraFieldView, offsetExtraField) == EXTRAFIELD_TYPE_ZIP64) {
7943
+ return removeExtraFieldZip64(concat(
7944
+ rawExtraField.subarray(0, offsetExtraField),
7945
+ rawExtraField.subarray(Math.min(offsetExtraField + size, getLength(rawExtraField)))));
7946
+ }
7947
+ offsetExtraField += size;
7948
+ }
7949
+ return rawExtraField;
7950
+ }
7951
+
7928
7952
  async function copyZipData(zipWriter, reader, entries, directoryOffset) {
7929
7953
  const { writer } = zipWriter;
7930
7954
  const entryPositions = new Map();
@@ -9492,7 +9516,7 @@ function keepsContentType(writer, data) {
9492
9516
  } else if (writer.constructor == BlobWriter) {
9493
9517
  return data.type == contentType;
9494
9518
  } else if (writer.constructor == Data64URIWriter) {
9495
- return data.startsWith(writer.data);
9519
+ return data.startsWith("data:" + (contentType || "") + ";base64,");
9496
9520
  } else {
9497
9521
  return true;
9498
9522
  }
@@ -10165,6 +10189,7 @@ exports.ERR_UNSUPPORTED_ENCRYPTION = ERR_UNSUPPORTED_ENCRYPTION;
10165
10189
  exports.ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH = ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH;
10166
10190
  exports.ERR_UNSUPPORTED_ENCRYPTION_USDZ = ERR_UNSUPPORTED_ENCRYPTION_USDZ;
10167
10191
  exports.ERR_UNSUPPORTED_FORMAT = ERR_UNSUPPORTED_FORMAT;
10192
+ exports.ERR_UNSUPPORTED_UINT64 = ERR_UNSUPPORTED_UINT64;
10168
10193
  exports.ERR_WORKER_STARTUP_TIMEOUT = ERR_WORKER_STARTUP_TIMEOUT;
10169
10194
  exports.ERR_WRITER_NOT_INITIALIZED = ERR_WRITER_NOT_INITIALIZED;
10170
10195
  exports.ERR_ZIP_NOT_EMPTY = ERR_ZIP_NOT_EMPTY;