@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.
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zip-js/zip-js",
3
- "version": "2.8.54",
3
+ "version": "2.8.55",
4
4
  "exports": {
5
5
  ".": "./index.js",
6
6
  "./external": "./lib/zip-fs-external.js",
@@ -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;
@@ -4808,6 +4809,7 @@ class ZipReader {
4808
4809
  let startOffset;
4809
4810
  let zip64EndOfDirectory;
4810
4811
  let zip64EndOfDirectoryVersion2;
4812
+ let zip64EndOfDirectoryLength = ZIP64_END_OF_CENTRAL_DIR_LENGTH;
4811
4813
  let directoryEncryptionInfo;
4812
4814
  const requiresZip64 = directoryDataOffset == MAX_32_BITS || directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS || diskNumber == MAX_16_BITS;
4813
4815
  if (directoryDataOffset != MAX_32_BITS && diskNumber != MAX_16_BITS) {
@@ -4844,6 +4846,7 @@ class ZipReader {
4844
4846
  Number(getBigUint64(endOfDirectoryView, 4)) - (ZIP64_END_OF_CENTRAL_DIR_LENGTH - 12),
4845
4847
  reader.size - directoryDataOffset - ZIP64_END_OF_CENTRAL_DIR_LENGTH);
4846
4848
  if (extensibleDataLength > 0) {
4849
+ zip64EndOfDirectoryLength += extensibleDataLength;
4847
4850
  const rawExtensibleData = await readUint8Array(reader, directoryDataOffset + ZIP64_END_OF_CENTRAL_DIR_LENGTH, extensibleDataLength);
4848
4851
  directoryEncryptionInfo = getDirectoryEncryptionInfo(rawExtensibleData);
4849
4852
  }
@@ -4873,7 +4876,7 @@ class ZipReader {
4873
4876
  }
4874
4877
  let declaredDirectoryDataLength = directoryDataLength;
4875
4878
  const centralDirectoryEndOffset = endOfDirectoryInfo.offset -
4876
- (zip64EndOfDirectory ? ZIP64_END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
4879
+ (zip64EndOfDirectory ? zip64EndOfDirectoryLength + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH : 0);
4877
4880
  if (directoryDataOffset >= reader.size) {
4878
4881
  prependedDataLength = reader.size - directoryDataOffset - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
4879
4882
  directoryDataOffset = reader.size - directoryDataLength - END_OF_CENTRAL_DIR_LENGTH;
@@ -4893,7 +4896,9 @@ class ZipReader {
4893
4896
  }
4894
4897
  const expectedDirectoryDataOffset = centralDirectoryEndOffset - directoryDataLength;
4895
4898
  if (directoryDataOffset != expectedDirectoryDataOffset && diskNumber == lastDiskNumber) {
4896
- const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE;
4899
+ const storedPointsAtDirectory = getUint32$1(directoryView, offset) == CENTRAL_FILE_HEADER_SIGNATURE ||
4900
+ Boolean(directoryEncryptionInfo && directoryEncryptionInfo.compressedSize) ||
4901
+ detectEncryptedCentralDirectory(directoryView);
4897
4902
  let reconcile = !storedPointsAtDirectory;
4898
4903
  if (!reconcile && expectedDirectoryDataOffset >= 0 && expectedDirectoryDataOffset + 4 <= reader.size) {
4899
4904
  const expectedSignatureArray = await readUint8Array(reader, expectedDirectoryDataOffset, 4);
@@ -4922,11 +4927,13 @@ class ZipReader {
4922
4927
  zipReader.directoryOffset = directoryDataOffset;
4923
4928
  zipReader.directoryLength = declaredDirectoryDataLength;
4924
4929
  const decryptCentralDirectory = getFunctionOptionValue$1(zipReader, options, OPTION_DECRYPT_CENTRAL_DIRECTORY);
4925
- let decryptedDirectory;
4930
+ let decryptedDirectory, dataAfterEncryptedDirectory;
4926
4931
  if (decryptCentralDirectory && filesLength && directoryArray.length >= 4 &&
4927
4932
  getUint32$1(directoryView, 0) != CENTRAL_FILE_HEADER_SIGNATURE &&
4928
4933
  (zip64EndOfDirectoryVersion2 || detectEncryptedCentralDirectory(directoryView))) {
4929
- directoryArray = await decryptCentralDirectory(directoryArray, directoryEncryptionInfo);
4934
+ const encryptedDirectoryDataLength = getEncryptedDirectoryDataLength(directoryEncryptionInfo, declaredDirectoryDataLength, directoryArray.length);
4935
+ dataAfterEncryptedDirectory = directoryArray.subarray(encryptedDirectoryDataLength);
4936
+ directoryArray = await decryptCentralDirectory(directoryArray.subarray(0, encryptedDirectoryDataLength), directoryEncryptionInfo);
4930
4937
  directoryView = getDataView(directoryArray);
4931
4938
  declaredDirectoryDataLength = directoryArray.length;
4932
4939
  decryptedDirectory = true;
@@ -4992,6 +4999,7 @@ class ZipReader {
4992
4999
  }
4993
5000
  Object.assign(fileEntry, {
4994
5001
  index: indexFile,
5002
+ decryptedDirectory,
4995
5003
  versionMadeBy,
4996
5004
  msDosCompatible,
4997
5005
  zip64: false,
@@ -5068,12 +5076,11 @@ class ZipReader {
5068
5076
  yield entry;
5069
5077
  }
5070
5078
  let offsetAfterSignature = offset;
5071
- if (offset + 6 <= directoryArray.length && getUint32$1(directoryView, offset) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
5072
- const signatureDataLength = getUint16$1(directoryView, offset + 4);
5073
- if (offset + 6 + signatureDataLength <= directoryArray.length) {
5074
- zipReader.digitalSignature = directoryArray.subarray(offset + 6, offset + 6 + signatureDataLength);
5075
- offsetAfterSignature = offset + 6 + signatureDataLength;
5076
- }
5079
+ const digitalSignature = readDigitalSignature(directoryArray.subarray(offset)) ||
5080
+ (decryptedDirectory ? readDigitalSignature(dataAfterEncryptedDirectory) : UNDEFINED_VALUE);
5081
+ if (digitalSignature) {
5082
+ zipReader.digitalSignature = digitalSignature;
5083
+ offsetAfterSignature = offset + 6 + digitalSignature.length;
5077
5084
  }
5078
5085
  if (checkAmbiguity && offset != declaredDirectoryDataLength && offsetAfterSignature != declaredDirectoryDataLength) {
5079
5086
  throwAmbiguousArchive("trailing central directory data");
@@ -5382,6 +5389,27 @@ function detectEncryptedCentralDirectory(directoryView) {
5382
5389
  return false;
5383
5390
  }
5384
5391
 
5392
+ function readDigitalSignature(signatureRecordArray) {
5393
+ if (signatureRecordArray.length >= 6) {
5394
+ const signatureRecordView = getDataView(signatureRecordArray);
5395
+ if (getUint32$1(signatureRecordView, 0) == DIGITAL_SIGNATURE_RECORD_SIGNATURE) {
5396
+ const signatureDataLength = getUint16$1(signatureRecordView, 4);
5397
+ if (6 + signatureDataLength <= signatureRecordArray.length) {
5398
+ return signatureRecordArray.subarray(6, 6 + signatureDataLength);
5399
+ }
5400
+ }
5401
+ }
5402
+ }
5403
+
5404
+ function getEncryptedDirectoryDataLength(directoryEncryptionInfo, declaredDirectoryDataLength, directoryDataLength) {
5405
+ const encryptedDirectoryDataLength = directoryEncryptionInfo && directoryEncryptionInfo.compressedSize ?
5406
+ directoryEncryptionInfo.compressedSize :
5407
+ declaredDirectoryDataLength;
5408
+ return encryptedDirectoryDataLength > 0 && encryptedDirectoryDataLength <= directoryDataLength ?
5409
+ encryptedDirectoryDataLength :
5410
+ directoryDataLength;
5411
+ }
5412
+
5385
5413
  function getDirectoryEncryptionInfo(rawExtensibleData) {
5386
5414
  const directoryEncryptionInfo = { rawExtensibleData };
5387
5415
  if (rawExtensibleData.length >= 28) {
@@ -5966,7 +5994,9 @@ async function readSignature(reader, view, anchoredOffset, signatureOffset, size
5966
5994
 
5967
5995
  function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, checkLocalFilename) {
5968
5996
  const { rawFilename } = zipEntry;
5969
- if (checkLocalFilename &&
5997
+ const maskedLocalDirectory = zipEntry.decryptedDirectory &&
5998
+ (localDirectory.rawBitFlag & BITFLAG_MASKED_LOCAL_HEADERS) == BITFLAG_MASKED_LOCAL_HEADERS;
5999
+ if (checkLocalFilename && !maskedLocalDirectory &&
5970
6000
  (rawLocalFilename.length != rawFilename.length ||
5971
6001
  rawLocalFilename.some((byteValue, indexByte) => byteValue != rawFilename[indexByte]))) {
5972
6002
  throwAmbiguousArchive("mismatched local file header (filename)");
@@ -5977,7 +6007,7 @@ function validateLocalDirectory(zipEntry, localDirectory, rawLocalFilename, chec
5977
6007
  if (localDirectory.compressionMethod != zipEntry.compressionMethod) {
5978
6008
  throwAmbiguousArchive("mismatched local file header (compression method)");
5979
6009
  }
5980
- if (!localDirectory.bitFlag.dataDescriptor &&
6010
+ if (!localDirectory.bitFlag.dataDescriptor && !maskedLocalDirectory &&
5981
6011
  (localDirectory.crc32 || localDirectory.compressedSize || localDirectory.uncompressedSize) &&
5982
6012
  (localDirectory.crc32 != zipEntry.crc32 ||
5983
6013
  localDirectory.compressedSize != zipEntry.compressedSize ||
@@ -6108,6 +6138,7 @@ const MIN_NTFS_TIME = BigInt(0);
6108
6138
  const MAX_NTFS_TIME = BigInt("0x7fffffffffffffff");
6109
6139
  const ERR_UNSUPPORTED_FORMAT = "Zip64 is not supported (set the 'zip64' option to 'true')";
6110
6140
  const ERR_UNDEFINED_UNCOMPRESSED_SIZE = "Undefined uncompressed size";
6141
+ const ERR_UNDEFINED_COMPRESSION_METHOD = "Undefined compression method";
6111
6142
  const ERR_UNDETERMINED_SIZE = "Undetermined size";
6112
6143
  const ERR_UNDEFINED_READER = "Undefined reader";
6113
6144
  const ERR_ZIP_NOT_EMPTY = "Zip file not empty";
@@ -6635,6 +6666,9 @@ function resolveMetadata(zipWriter, name, options) {
6635
6666
  level = 0;
6636
6667
  }
6637
6668
  }
6669
+ if (passThrough) {
6670
+ level = UNDEFINED_VALUE;
6671
+ }
6638
6672
  let useCompressionStream = getOptionValue(zipWriter, options, OPTION_USE_COMPRESSION_STREAM);
6639
6673
  let dataDescriptor = getOptionValue(zipWriter, options, OPTION_DATA_DESCRIPTOR);
6640
6674
  if (bufferedWrite && dataDescriptor === UNDEFINED_VALUE) {
@@ -6746,6 +6780,9 @@ function resolveEntrySizes(zipWriter, hasContent, contentSize, metadata, options
6746
6780
  if (uncompressedSize === UNDEFINED_VALUE) {
6747
6781
  throw new Error(ERR_UNDEFINED_UNCOMPRESSED_SIZE);
6748
6782
  }
6783
+ if (compressionMethod === UNDEFINED_VALUE) {
6784
+ throw new Error(ERR_UNDEFINED_COMPRESSION_METHOD);
6785
+ }
6749
6786
  }
6750
6787
  const zip64Enabled = zip64 === true;
6751
6788
  const encrypted = getOptionValue(zipWriter, options, PROPERTY_NAME_ENCRYPTED);
@@ -8924,4 +8961,4 @@ function terminateWorkersAndModule() {
8924
8961
 
8925
8962
  configureExternalAssets();
8926
8963
 
8927
- export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, 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_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_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_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, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };
8964
+ export { BlobReader, BlobWriter, Data64URIReader, Data64URIWriter, 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_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_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_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, ZipReader, ZipReaderStream, ZipWriter, ZipWriterStream, configure, createBlobTempStream, createOPFSTempStream, createSyncAccessHandleTempStream, getMimeType, registerCodec, resetConfiguration, terminateWorkersAndModule as terminateWorkers, unregisterCodec };