@zip.js/zip.js 2.17.0 → 2.18.0

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.17.0",
3
+ "version": "2.18.0",
4
4
  "exports": {
5
5
  ".": "./index.js",
6
6
  "./external": "./lib/zip-fs-external.js",
@@ -3280,8 +3280,13 @@ function getResponseError(errorData, errorValue) {
3280
3280
  if (codecImportFailed) {
3281
3281
  responseError.codecImportFailed = true;
3282
3282
  }
3283
- if (cause && !isErrorObject(responseError.cause)) {
3284
- responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
3283
+ if (cause) {
3284
+ if (!isErrorObject(responseError.cause)) {
3285
+ responseError.cause = Object.assign(new Error(cause.message), { name: cause.name });
3286
+ }
3287
+ if (cause.code !== UNDEFINED_VALUE && responseError.cause.code !== cause.code) {
3288
+ responseError.cause.code = cause.code;
3289
+ }
3285
3290
  }
3286
3291
  if (errorValue) {
3287
3292
  if (responseError.name !== name) {
@@ -4853,7 +4858,7 @@ const PARENT_DIRECTORY_REGEXP = /(^|[\\/])\.\.([\\/]|$)/;
4853
4858
  const CHARSET_UTF8 = "utf-8";
4854
4859
  const PROPERTY_NAME_UTF8_SUFFIX = "UTF8";
4855
4860
  const CHARSET_CP437 = "cp437";
4856
- const BITFLAG_AMBIGUITY_MASK = BITFLAG_ENCRYPTED | BITFLAG_DATA_DESCRIPTOR | BITFLAG_LANG_ENCODING_FLAG;
4861
+ const BITFLAG_AMBIGUITY_MASK = BITFLAG_ENCRYPTED | BITFLAG_DATA_DESCRIPTOR | BITFLAG_STRONG_ENCRYPTION | BITFLAG_LANG_ENCODING_FLAG;
4857
4862
  const VENDOR_VERSION_AE_1$1 = 1;
4858
4863
  const ZIP64_PROPERTIES = [
4859
4864
  [PROPERTY_NAME_UNCOMPRESSED_SIZE, MAX_32_BITS],
@@ -5507,12 +5512,12 @@ class ZipEntry {
5507
5512
  fileEntry.gid = gid;
5508
5513
  }
5509
5514
  const checkPasswordOnly = getOptionValue$1(zipEntry, options, OPTION_CHECK_PASSWORD_ONLY);
5510
- const encrypted = zipEntry.encrypted && localDirectory.encrypted && (!passThroughEncryption || checkPasswordOnly);
5515
+ const encrypted = zipEntry.encrypted && (!passThroughEncryption || checkPasswordOnly);
5511
5516
  const zipCrypto = encrypted && !extraFieldAES;
5512
5517
  if (!passThroughEncryption) {
5513
5518
  fileEntry.zipCrypto = zipCrypto;
5514
5519
  }
5515
- if (encrypted && (localDirectory.rawBitFlag & BITFLAG_STRONG_ENCRYPTION) == BITFLAG_STRONG_ENCRYPTION) {
5520
+ if (encrypted && (zipEntry.rawBitFlag & BITFLAG_STRONG_ENCRYPTION) == BITFLAG_STRONG_ENCRYPTION) {
5516
5521
  throw new Error(ERR_UNSUPPORTED_ENCRYPTION);
5517
5522
  }
5518
5523
  const registeredCodec = passThroughCompression ? UNDEFINED_VALUE : getRegisteredCodec(compressionMethod);
@@ -5752,8 +5757,16 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5752
5757
  });
5753
5758
  const extraFieldZip64 = extraField.get(EXTRAFIELD_TYPE_ZIP64);
5754
5759
  if (extraFieldZip64) {
5755
- readExtraFieldZip64(extraFieldZip64, directory);
5760
+ if (!readExtraFieldZip64(extraFieldZip64, directory, localDirectory)) {
5761
+ malformedExtraField = true;
5762
+ }
5756
5763
  directory.extraFieldZip64 = extraFieldZip64;
5764
+ } else if (ZIP64_PROPERTIES.some(([propertyName, max]) => directory[propertyName] == max)) {
5765
+ if (localDirectory) {
5766
+ malformedExtraField = true;
5767
+ } else {
5768
+ throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
5769
+ }
5757
5770
  }
5758
5771
  const extraFieldUnicodePath = extraField.get(EXTRAFIELD_TYPE_UNICODE_PATH);
5759
5772
  if (extraFieldUnicodePath) {
@@ -5766,10 +5779,13 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5766
5779
  directory.extraFieldUnicodeComment = extraFieldUnicodeComment;
5767
5780
  }
5768
5781
  const extraFieldAES = extraField.get(EXTRAFIELD_TYPE_AES);
5769
- if (extraFieldAES && extraFieldAES.data.length >= 7) {
5782
+ if (extraFieldAES && (compressionMethod == COMPRESSION_METHOD_AES || directory.encrypted) && extraFieldAES.data.length >= 7) {
5770
5783
  readExtraFieldAES(extraFieldAES, directory, compressionMethod);
5771
5784
  directory.extraFieldAES = extraFieldAES;
5772
5785
  } else {
5786
+ if (extraFieldAES) {
5787
+ malformedExtraField = true;
5788
+ }
5773
5789
  directory.compressionMethod = compressionMethod;
5774
5790
  }
5775
5791
  const extraFieldPkwareUnix = extraField.get(EXTRAFIELD_TYPE_PKWARE_UNIX);
@@ -5812,20 +5828,35 @@ function readCommonFooter(fileEntry, directory, dataView, offset, localDirectory
5812
5828
  return malformedExtraField;
5813
5829
  }
5814
5830
 
5815
- function readExtraFieldZip64(extraFieldZip64, directory) {
5831
+ function readExtraFieldZip64(extraFieldZip64, directory, localDirectory) {
5816
5832
  directory.zip64 = true;
5817
5833
  const extraFieldView = getDataView(extraFieldZip64.data);
5818
5834
  const missingProperties = ZIP64_PROPERTIES.filter(([propertyName, max]) => directory[propertyName] == max);
5819
5835
  const requiredLength = missingProperties.reduce((length, [, max]) => length + ZIP64_EXTRACTION[max].bytes, 0);
5820
5836
  if (extraFieldZip64.data.length < requiredLength) {
5837
+ if (localDirectory) {
5838
+ return false;
5839
+ }
5821
5840
  throw new Error(ERR_EXTRAFIELD_ZIP64_NOT_FOUND);
5822
5841
  }
5823
- for (let indexMissingProperty = 0, offset = 0; indexMissingProperty < missingProperties.length; indexMissingProperty++) {
5824
- const [propertyName, max] = missingProperties[indexMissingProperty];
5825
- const extraction = ZIP64_EXTRACTION[max];
5826
- directory[propertyName] = extraFieldZip64[propertyName] = extraction.getValue(extraFieldView, offset);
5827
- offset += extraction.bytes;
5842
+ const values = [];
5843
+ try {
5844
+ for (let indexMissingProperty = 0, offset = 0; indexMissingProperty < missingProperties.length; indexMissingProperty++) {
5845
+ const [, max] = missingProperties[indexMissingProperty];
5846
+ const extraction = ZIP64_EXTRACTION[max];
5847
+ values.push(extraction.getValue(extraFieldView, offset));
5848
+ offset += extraction.bytes;
5849
+ }
5850
+ } catch (error) {
5851
+ if (localDirectory) {
5852
+ return false;
5853
+ }
5854
+ throw error;
5828
5855
  }
5856
+ missingProperties.forEach(([propertyName], indexMissingProperty) => {
5857
+ directory[propertyName] = extraFieldZip64[propertyName] = values[indexMissingProperty];
5858
+ });
5859
+ return true;
5829
5860
  }
5830
5861
 
5831
5862
  function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName, directory, fileEntry) {
@@ -8931,7 +8962,7 @@ function formatSupported(StreamClass, format) {
8931
8962
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8932
8963
  */
8933
8964
 
8934
- const VERSION = "2.17.0";
8965
+ const VERSION = "2.18.0";
8935
8966
 
8936
8967
  /*
8937
8968
  Copyright (c) 2025 Gildas Lormeau. All rights reserved.