@zip.js/zip.js 2.8.54 → 2.8.55

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.
@@ -76,6 +76,7 @@ const BITFLAG_LEVEL_SUPER_FAST_MASK = 0b110;
76
76
  const BITFLAG_DATA_DESCRIPTOR = 0b1000;
77
77
  const BITFLAG_STRONG_ENCRYPTION = 0b1000000;
78
78
  const BITFLAG_LANG_ENCODING_FLAG = 0b100000000000;
79
+ const BITFLAG_MASKED_LOCAL_HEADERS = 0b10000000000000;
79
80
  const FILE_ATTR_MSDOS_DIR_MASK = 0b10000;
80
81
  const FILE_ATTR_MSDOS_READONLY_MASK = 0x01;
81
82
  const FILE_ATTR_MSDOS_HIDDEN_MASK = 0x02;
@@ -4828,6 +4829,7 @@ class ZipReader {
4828
4829
  let startOffset;
4829
4830
  let zip64EndOfDirectory;
4830
4831
  let zip64EndOfDirectoryVersion2;
4832
+ let zip64EndOfDirectoryLength = ZIP64_END_OF_CENTRAL_DIR_LENGTH;
4831
4833
  let directoryEncryptionInfo;
4832
4834
  const requiresZip64 = directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS;
4833
4835
  if (directoryDataOffset != MAX_32_BITS && diskNumber != MAX_16_BITS) {
@@ -4864,6 +4866,7 @@ class ZipReader {
4864
4866
  Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4865
4867
  reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4866
4868
  if (extensibleDataLength > 0) {
4869
+ zip64EndOfDirectoryLength += extensibleDataLength;
4867
4870
  const rawExtensibleData = await readUint8Array(reader, directoryDataOffset + ZIP64_END_OF_CENTRAL_DIR_LENGTH, extensibleDataLength);
4868
4871
  directoryEncryptionInfo = getDirectoryEncryptionInfo(rawExtensibleData);
4869
4872
  }
@@ -4893,7 +4896,7 @@ class ZipReader {
4893
4896
  }
4894
4897
  let declaredDirectoryDataLength = directoryDataLength;
4895
4898
  const centralDirectoryEndOffset = endOfDirectoryInfo.offset -
4896
- (zip64EndOfDirectory ? ZIP64_END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
4899
+ (zip64EndOfDirectory ? zip64EndOfDirectoryLength + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
4897
4900
  if (directoryDataOffset >= reader.size) {
4898
4901
  prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
4899
4902
  directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
@@ -4913,7 +4916,9 @@ class ZipReader {
4913
4916
  }
4914
4917
  const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
4915
4918
  if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
4916
- const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4919
+ const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE ||
4920
+ Boolean(directoryEncryptionInfo && directoryEncryptionInfo.compressedSize) ||
4921
+ detectEncryptedCentralDirectory(directoryView);
4917
4922
  let reconcile = !storedPointsAtDirectory;
4918
4923
  if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
4919
4924
  const expectedSignatureArray = await readUint8Array(reader, expectedDirectoryDataOffset, 4);
@@ -4942,11 +4947,13 @@ class ZipReader {
4942
4947
  zipReader.directoryOffset = directoryDataOffset;
4943
4948
  zipReader.directoryLength = declaredDirectoryDataLength;
4944
4949
  const decryptCentralDirectory = getFunctionOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4945
- let decryptedDirectory;
4950
+ let decryptedDirectory, dataAfterEncryptedDirectory;
4946
4951
  if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
4947
4952
  getUint32$1(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4948
4953
  (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4949
- directoryArray = await decryptCentralDirectory(directoryArray, directoryEncryptionInfo);
4954
+ const encryptedDirectoryDataLength = getEncryptedDirectoryDataLength(directoryEncryptionInfo, declaredDirectoryDataLength, directoryArray.length);
4955
+ dataAfterEncryptedDirectory = directoryArray.subarray(encryptedDirectoryDataLength);
4956
+ directoryArray = await decryptCentralDirectory(directoryArray.subarray(0, encryptedDirectoryDataLength), directoryEncryptionInfo);
4950
4957
  directoryView = getDataView(directoryArray);
4951
4958
  declaredDirectoryDataLength = directoryArray.length;
4952
4959
  decryptedDirectory = true;
@@ -5012,6 +5019,7 @@ class ZipReader {
5012
5019
  }
5013
5020
  Object.assign(fileEntry, {
5014
5021
  index: indexFile,
5022
+ decryptedDirectory,
5015
5023
  versionMadeBy,
5016
5024
  msDosCompatible,
5017
5025
  zip64: false,
@@ -5088,12 +5096,11 @@ class ZipReader {
5088
5096
  yield entry;
5089
5097
  }
5090
5098
  let offsetAfterSignature = offset;
5091
- if (offset + 6 <= directoryArray.length && getUint32$1(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
5092
- const signatureDataLength = getUint16$1(directoryView, offset + 4);
5093
- if (offset + 6 + signatureDataLength <= directoryArray.length) {
5094
- zipReader.digitalSignature = directoryArray.subarray(offset + 6, offset + 6 + signatureDataLength);
5095
- offsetAfterSignature = offset + 6 + signatureDataLength;
5096
- }
5099
+ const digitalSignature = readDigitalSignature(directoryArray.subarray(offset)) ||
5100
+ (decryptedDirectory ? readDigitalSignature(dataAfterEncryptedDirectory) : UNDEFINED_VALUE);
5101
+ if (digitalSignature) {
5102
+ zipReader.digitalSignature = digitalSignature;
5103
+ offsetAfterSignature = offset + 6 + digitalSignature.length;
5097
5104
  }
5098
5105
  if (checkAmbiguity && offset != declaredDirectoryDataLength && offsetAfterSignature != declaredDirectoryDataLength) {
5099
5106
  throwAmbiguousArchive("trailing central directory data");
@@ -5402,6 +5409,27 @@ function detectEncryptedCentralDirectory(directoryView) {
5402
5409
  return false;
5403
5410
  }
5404
5411
 
5412
+ function readDigitalSignature(signatureRecordArray) {
5413
+ if (signatureRecordArray.length >= 6) {
5414
+ const signatureRecordView = getDataView(signatureRecordArray);
5415
+ if (getUint32$1(signatureRecordView, 0) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
5416
+ const signatureDataLength = getUint16$1(signatureRecordView, 4);
5417
+ if (6 + signatureDataLength <= signatureRecordArray.length) {
5418
+ return signatureRecordArray.subarray(6, 6 + signatureDataLength);
5419
+ }
5420
+ }
5421
+ }
5422
+ }
5423
+
5424
+ function getEncryptedDirectoryDataLength(directoryEncryptionInfo, declaredDirectoryDataLength, directoryDataLength) {
5425
+ const encryptedDirectoryDataLength = directoryEncryptionInfo && directoryEncryptionInfo.compressedSize ?
5426
+ directoryEncryptionInfo.compressedSize :
5427
+ declaredDirectoryDataLength;
5428
+ return encryptedDirectoryDataLength > 0 && encryptedDirectoryDataLength <= directoryDataLength ?
5429
+ encryptedDirectoryDataLength :
5430
+ directoryDataLength;
5431
+ }
5432
+
5405
5433
  function getDirectoryEncryptionInfo(rawExtensibleData) {
5406
5434
  const directoryEncryptionInfo = { rawExtensibleData };
5407
5435
  if (rawExtensibleData.length >= 28) {
@@ -5986,7 +6014,9 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
5986
6014
 
5987
6015
  function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
5988
6016
  const { rawFilename } = zipEntry;
5989
- if (checkLocalFilename &&
6017
+ const maskedLocalDirectory = zipEntry.decryptedDirectory &&
6018
+ (localDirectory.rawBitFlag & BITFLAG_MASKED_LOCAL_HEADERS) == BITFLAG_MASKED_LOCAL_HEADERS;
6019
+ if (checkLocalFilename && !maskedLocalDirectory &&
5990
6020
  (rawLocalFilename.length != rawFilename.length ||
5991
6021
  rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
5992
6022
  throwAmbiguousArchive("mismatched local file header (filename)");
@@ -5997,7 +6027,7 @@ function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, chec
5997
6027
  if (localDirectory.compressionMethod != zipEntry.compressionMethod) {
5998
6028
  throwAmbiguousArchive("mismatched local file header (compression method)");
5999
6029
  }
6000
- if (!localDirectory.bitFlag.dataDescriptor &&
6030
+ if (!localDirectory.bitFlag.dataDescriptor && !maskedLocalDirectory &&
6001
6031
  (localDirectory.crc32 || localDirectory.compressedSize || localDirectory.uncompressedSize) &&
6002
6032
  (localDirectory.crc32 != zipEntry.crc32 ||
6003
6033
  localDirectory.compressedSize != zipEntry.compressedSize ||
@@ -6128,6 +6158,7 @@ const MIN_NTFS_TIME = BigInt(0);
6128
6158
  const MAX_NTFS_TIME = BigInt("0x7fffffffffffffff");
6129
6159
  const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
6130
6160
  const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
6161
+ const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6131
6162
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6132
6163
  const ERR_UNDEFINED_READER = "Undefined reader";
6133
6164
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
@@ -6655,6 +6686,9 @@ function resolveMetadata(zipWriter, name, options) {
6655
6686
  level = 0;
6656
6687
  }
6657
6688
  }
6689
+ if (passThrough) {
6690
+ level = UNDEFINED_VALUE;
6691
+ }
6658
6692
  let useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
6659
6693
  let dataDescriptor = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR);
6660
6694
  if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
@@ -6766,6 +6800,9 @@ function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options
6766
6800
  if (uncompressedSize === UNDEFINED_VALUE) {
6767
6801
  throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
6768
6802
  }
6803
+ if (compressionMethod === UNDEFINED_VALUE) {
6804
+ throw new Error(ERR_UNDEFINED_COMPRESSION_METHOD);
6805
+ }
6769
6806
  }
6770
6807
  const zip64Enabled = zip64 === true;
6771
6808
  const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
@@ -9953,10 +9990,7 @@ function getChildEntryOptions(child, selectedEntry, options) {
9953
9990
  });
9954
9991
  }
9955
9992
  if (isPassThrough(child, options)) {
9956
- let level, encryptionStrength;
9957
- if (compressionMethod === 0) {
9958
- level = 0;
9959
- }
9993
+ let encryptionStrength;
9960
9994
  if (extraFieldAES) {
9961
9995
  encryptionStrength = extraFieldAES.strength;
9962
9996
  }
@@ -9966,7 +10000,6 @@ function getChildEntryOptions(child, selectedEntry, options) {
9966
10000
  zipCrypto,
9967
10001
  crc32,
9968
10002
  uncompressedSize,
9969
- level,
9970
10003
  encryptionStrength,
9971
10004
  compressionMethod
9972
10005
  };
@@ -10381,4 +10414,4 @@ function decodeMimeTypes(data) {
10381
10414
  return mimeTypes;
10382
10415
  }
10383
10416
 
10384
- export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMMENT_TYPE, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_DATE, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_COMMENT_TYPE, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_DATA_TYPE, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_FUNCTION_OPTION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MAX_WORKERS, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_PASS_THROUGH, ERR_INVALID_READER_OPTIONS, ERR_INVALID_SIGNAL, ERR_INVALID_SIGNATURE, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_STRICTNESS, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_READABLE_CONSUMED, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipDirectoryEntry, ZipEntry, ZipFS, ZipFileEntry, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
10417
+ export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, ERR_ABORTED, ERR_AMBIGUOUS_ARCHIVE, ERR_BAD_FORMAT, ERR_CENTRAL_DIRECTORY_NOT_FOUND, ERR_DUPLICATED_NAME, ERR_ENCRYPTED, ERR_ENCRYPTED_CENTRAL_DIRECTORY, ERR_ENTRY_DATA_OUT_OF_BOUNDS, ERR_ENTRY_EXISTS, ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND, ERR_EOCDR_NOT_FOUND, ERR_EXTRAFIELD_ZIP64_NOT_FOUND, ERR_HTTP_RANGE, ERR_HTTP_RESOURCE_CHANGED, ERR_INVALID_AUTHENTICATION_CODE, ERR_INVALID_CODEC_DEFINITION, ERR_INVALID_CODEC_MODULE, ERR_INVALID_COMMENT, ERR_INVALID_COMMENT_TYPE, ERR_INVALID_COMPRESSED_DATA, ERR_INVALID_CRC32, ERR_INVALID_DATE, ERR_INVALID_ENCRYPTION_STRENGTH, ERR_INVALID_ENTRY_COMMENT, ERR_INVALID_ENTRY_COMMENT_TYPE, ERR_INVALID_ENTRY_NAME, ERR_INVALID_EXTRAFIELD, ERR_INVALID_EXTRAFIELD_DATA, ERR_INVALID_EXTRAFIELD_DATA_TYPE, ERR_INVALID_EXTRAFIELD_TYPE, ERR_INVALID_FILENAME_VALIDATION, ERR_INVALID_FUNCTION_OPTION, ERR_INVALID_GID, ERR_INVALID_LEVEL, ERR_INVALID_MAX_APPENDED_DATA_SIZE, ERR_INVALID_MAX_WORKERS, ERR_INVALID_MSDOS_ATTRIBUTES, ERR_INVALID_MSDOS_DATA, ERR_INVALID_PASSWORD, ERR_INVALID_PASSWORD_TYPE, ERR_INVALID_PASS_THROUGH, ERR_INVALID_READER_OPTIONS, ERR_INVALID_SIGNAL, ERR_INVALID_SIGNATURE, ERR_INVALID_SIGNATURE_DATA, ERR_INVALID_STRICTNESS, ERR_INVALID_UID, ERR_INVALID_UNCOMPRESSED_SIZE, ERR_INVALID_UNIX_EXTRA_FIELD_TYPE, ERR_INVALID_UNIX_ID_SIZE, ERR_INVALID_UNIX_MODE, ERR_INVALID_VERSION, ERR_ITERATOR_COMPLETED_TOO_SOON, ERR_LOCAL_FILE_HEADER_NOT_FOUND, ERR_OVERLAPPING_ENTRY, ERR_READABLE_CONSUMED, ERR_RESERVED_COMPRESSION_METHOD, ERR_SPLIT_ZIP_FILE, ERR_UNDEFINED_COMPRESSION_METHOD, ERR_UNDEFINED_READER, ERR_UNDEFINED_UNCOMPRESSED_SIZE, ERR_UNDETERMINED_SIZE, ERR_UNSAFE_FILENAME, ERR_UNSUPPORTED_COMPRESSION$1 as ERR_UNSUPPORTED_COMPRESSION, ERR_UNSUPPORTED_CONTEXT, ERR_UNSUPPORTED_CRYPTO_API, ERR_UNSUPPORTED_ENCRYPTION, ERR_UNSUPPORTED_ENCRYPTION_PASS_THROUGH, ERR_UNSUPPORTED_ENCRYPTION_USDZ, ERR_UNSUPPORTED_FORMAT, ERR_WORKER_STARTUP_TIMEOUT, ERR_WRITER_NOT_INITIALIZED, ERR_ZIP_NOT_EMPTY, HttpRangeReader, HttpReader, Reader, SplitDataReader, SplitDataWriter, TextReader, TextWriter, Uint8ArrayReader, Uint8ArrayWriter, Writer, ZipDirectoryEntry, ZipEntry, ZipFS, ZipFileEntry, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, fs, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };