@zip.js/zip.js 2.8.49 → 2.8.51

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.
@@ -140,6 +140,7 @@ import {
140
140
  UNDEFINED_VALUE,
141
141
  INFINITY_VALUE,
142
142
  OBJECT_TYPE,
143
+ STRING_TYPE,
143
144
  EMPTY_UINT8_ARRAY
144
145
  } from "./constants.js";
145
146
  import { getConfiguration } from "./configuration.js";
@@ -212,7 +213,9 @@ import {
212
213
  OPTION_USDZ,
213
214
  OPTION_UNIX_EXTRA_FIELD_TYPE,
214
215
  OPTION_LOCAL_EXTRA_FIELD,
215
- OPTION_SIGN_CENTRAL_DIRECTORY
216
+ OPTION_SIGN_CENTRAL_DIRECTORY,
217
+ TEXT_TYPE_FILENAME,
218
+ TEXT_TYPE_COMMENT
216
219
  } from "./options.js";
217
220
 
218
221
  const ERR_DUPLICATED_NAME = "File already exists";
@@ -240,6 +243,8 @@ const ERR_INVALID_UNIX_EXTRA_FIELD_TYPE = "Invalid unixExtraFieldType (must be '
240
243
  const ERR_INVALID_UNIX_ID_SIZE = "uid/gid must be 0..65535 for unixExtraFieldType 'unix' (use 'infozip' for larger ids)";
241
244
  const ERR_INVALID_MSDOS_ATTRIBUTES = "Invalid msdosAttributesRaw (must be integer 0..255)";
242
245
  const ERR_INVALID_MSDOS_DATA = "Invalid msdosAttributes (must be an object with boolean flags)";
246
+ const ERR_INVALID_LEVEL = "Invalid level (must be integer 0..9)";
247
+ const ERR_INVALID_PASSWORD_TYPE = "Invalid password (password must be a string, rawPassword must be a Uint8Array)";
243
248
  const ERR_INVALID_SIGNATURE_DATA = "Signature data exceeds 64KB";
244
249
 
245
250
  const EXTRAFIELD_DATA_AES = new Uint8Array([0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00]);
@@ -247,6 +252,7 @@ const EXTRAFIELD_OFFSET_AES_VENDOR_VERSION = 4;
247
252
  const VENDOR_VERSION_AE_1 = 1;
248
253
  const INFOZIP_EXTRA_FIELD_TYPE = "infozip";
249
254
  const UNIX_EXTRA_FIELD_TYPE = "unix";
255
+ const MAX_LEVEL = 9;
250
256
 
251
257
  let workers = 0;
252
258
  const pendingEntries = [];
@@ -409,7 +415,8 @@ class ZipWriter {
409
415
 
410
416
  remove(entry) {
411
417
  const { filenames, files } = this;
412
- if (typeof entry == "string") {
418
+ // deno-lint-ignore valid-typeof
419
+ if (typeof entry == STRING_TYPE) {
413
420
  entry = files.get(entry);
414
421
  }
415
422
  if (entry && entry.filename !== UNDEFINED_VALUE) {
@@ -528,6 +535,8 @@ export {
528
535
  ERR_INVALID_UNIX_ID_SIZE,
529
536
  ERR_INVALID_MSDOS_ATTRIBUTES,
530
537
  ERR_INVALID_MSDOS_DATA,
538
+ ERR_INVALID_LEVEL,
539
+ ERR_INVALID_PASSWORD_TYPE,
531
540
  ERR_UNSUPPORTED_CRYPTO_API
532
541
  };
533
542
 
@@ -574,20 +583,20 @@ function resolveAttributes(zipWriter, name, options) {
574
583
  let msDosCompatible = getOptionValue(zipWriter, options, PROPERTY_NAME_MS_DOS_COMPATIBLE);
575
584
  let versionMadeBy = getOptionValue(zipWriter, options, PROPERTY_NAME_VERSION_MADE_BY, msDosCompatible ? 20 : 768);
576
585
  const executable = getOptionValue(zipWriter, options, PROPERTY_NAME_EXECUTABLE);
577
- const uid = getOptionValue(zipWriter, options, PROPERTY_NAME_UID);
578
- const gid = getOptionValue(zipWriter, options, PROPERTY_NAME_GID);
579
- let unixMode = getOptionValue(zipWriter, options, PROPERTY_NAME_UNIX_MODE);
586
+ const uid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UID);
587
+ const gid = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_GID);
588
+ let unixMode = getNumberOptionValue(zipWriter, options, PROPERTY_NAME_UNIX_MODE);
580
589
  let unixExtraFieldType = getOptionValue(zipWriter, options, OPTION_UNIX_EXTRA_FIELD_TYPE);
581
590
  let setuid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETUID);
582
591
  let setgid = getOptionValue(zipWriter, options, PROPERTY_NAME_SETGID);
583
592
  let sticky = getOptionValue(zipWriter, options, PROPERTY_NAME_STICKY);
584
- if (uid !== UNDEFINED_VALUE && (uid < 0 || uid > MAX_32_BITS)) {
593
+ if (uid !== UNDEFINED_VALUE && (!Number.isInteger(uid) || uid < 0 || uid > MAX_32_BITS)) {
585
594
  throw new Error(ERR_INVALID_UID);
586
595
  }
587
- if (gid !== UNDEFINED_VALUE && (gid < 0 || gid > MAX_32_BITS)) {
596
+ if (gid !== UNDEFINED_VALUE && (!Number.isInteger(gid) || gid < 0 || gid > MAX_32_BITS)) {
588
597
  throw new Error(ERR_INVALID_GID);
589
598
  }
590
- if (unixMode !== UNDEFINED_VALUE && (unixMode < 0 || unixMode > MAX_16_BITS)) {
599
+ if (unixMode !== UNDEFINED_VALUE && (!Number.isInteger(unixMode) || unixMode < 0 || unixMode > MAX_16_BITS)) {
591
600
  throw new Error(ERR_INVALID_UNIX_MODE);
592
601
  }
593
602
  if (unixExtraFieldType !== UNDEFINED_VALUE && unixExtraFieldType !== INFOZIP_EXTRA_FIELD_TYPE && unixExtraFieldType !== UNIX_EXTRA_FIELD_TYPE) {
@@ -699,7 +708,7 @@ function resolveAttributes(zipWriter, name, options) {
699
708
 
700
709
  function resolveMetadata(zipWriter, name, options) {
701
710
  const encode = getOptionValue(zipWriter, options, OPTION_ENCODE_TEXT, encodeText);
702
- let rawFilename = encode(name);
711
+ let rawFilename = encode(name, TEXT_TYPE_FILENAME);
703
712
  if (rawFilename === UNDEFINED_VALUE) {
704
713
  rawFilename = encodeText(name);
705
714
  }
@@ -707,7 +716,7 @@ function resolveMetadata(zipWriter, name, options) {
707
716
  throw new Error(ERR_INVALID_ENTRY_NAME);
708
717
  }
709
718
  const comment = options[PROPERTY_NAME_COMMENT] || "";
710
- let rawComment = encode(comment);
719
+ let rawComment = encode(comment, TEXT_TYPE_COMMENT);
711
720
  if (rawComment === UNDEFINED_VALUE) {
712
721
  rawComment = encodeText(comment);
713
722
  }
@@ -727,8 +736,11 @@ function resolveMetadata(zipWriter, name, options) {
727
736
  if (!passThrough) {
728
737
  password = getOptionValue(zipWriter, options, OPTION_PASSWORD);
729
738
  rawPassword = getOptionValue(zipWriter, options, OPTION_RAW_PASSWORD);
739
+ if ((password && typeof password != STRING_TYPE) || (rawPassword && !(rawPassword instanceof Uint8Array))) {
740
+ throw new Error(ERR_INVALID_PASSWORD_TYPE);
741
+ }
730
742
  }
731
- const encryptionStrength = getOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
743
+ const encryptionStrength = getNumberOptionValue(zipWriter, options, OPTION_ENCRYPTION_STRENGTH, 3);
732
744
  const zipCrypto = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIPCRYPTO);
733
745
  const extendedTimestamp = getOptionValue(zipWriter, options, OPTION_EXTENDED_TIMESTAMP, true);
734
746
  const ntfsTimestamp = getOptionValue(zipWriter, options, OPTION_NTFS_TIMESTAMP);
@@ -746,7 +758,10 @@ function resolveMetadata(zipWriter, name, options) {
746
758
  compressionMethod !== COMPRESSION_METHOD_STORE && compressionMethod !== COMPRESSION_METHOD_DEFLATE && !registeredCodec) {
747
759
  throw new Error(ERR_UNSUPPORTED_COMPRESSION);
748
760
  }
749
- let level = getOptionValue(zipWriter, options, OPTION_LEVEL);
761
+ let level = getNumberOptionValue(zipWriter, options, OPTION_LEVEL);
762
+ if (level !== UNDEFINED_VALUE && (!Number.isInteger(level) || level < 0 || level > MAX_LEVEL)) {
763
+ throw new Error(ERR_INVALID_LEVEL);
764
+ }
750
765
  if (zipWriter.options[OPTION_USDZ]) {
751
766
  if (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) {
752
767
  throw new Error(ERR_UNSUPPORTED_ENCRYPTION_USDZ);
@@ -767,7 +782,7 @@ function resolveMetadata(zipWriter, name, options) {
767
782
  useCompressionStream = false;
768
783
  }
769
784
  const zip64 = getOptionValue(zipWriter, options, PROPERTY_NAME_ZIP64);
770
- if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(encryptionStrength >= 1 && encryptionStrength <= 3)) {
785
+ if (!zipCrypto && (password !== UNDEFINED_VALUE || rawPassword !== UNDEFINED_VALUE) && !(Number.isInteger(encryptionStrength) && encryptionStrength >= 1 && encryptionStrength <= 3)) {
771
786
  throw new Error(ERR_INVALID_ENCRYPTION_STRENGTH);
772
787
  }
773
788
  const rawExtraField = serializeExtraField(options[PROPERTY_NAME_EXTRA_FIELD]);
@@ -1961,6 +1976,14 @@ function getOptionValue(zipWriter, options, name, defaultValue) {
1961
1976
  return result === UNDEFINED_VALUE ? defaultValue : result;
1962
1977
  }
1963
1978
 
1979
+ function getNumberOptionValue(zipWriter, options, name, defaultValue) {
1980
+ return toNumber(getOptionValue(zipWriter, options, name, defaultValue));
1981
+ }
1982
+
1983
+ function toNumber(value) {
1984
+ return typeof value == STRING_TYPE && value.trim() ? Number(value) : value;
1985
+ }
1986
+
1964
1987
  function getMaximumCompressedSize(uncompressedSize) {
1965
1988
  return uncompressedSize + (5 * (Math.floor(uncompressedSize / 16383) + 1));
1966
1989
  }
@@ -26,6 +26,8 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
+ import "./core/codec-worker-web.js";
30
+
29
31
  export {
30
32
  ZipReader,
31
33
  ZipReaderStream,
@@ -48,5 +50,9 @@ export {
48
50
  ERR_OVERLAPPING_ENTRY,
49
51
  ERR_AMBIGUOUS_ARCHIVE,
50
52
  ERR_ENCRYPTED_CENTRAL_DIRECTORY,
53
+ ERR_UNSAFE_FILENAME,
54
+ ERR_INVALID_STRICTNESS,
55
+ ERR_INVALID_FILENAME_VALIDATION,
56
+ ERR_INVALID_MAX_APPENDED_DATA_SIZE,
51
57
  ERR_WORKER_STARTUP_TIMEOUT
52
58
  } from "./core/zip-reader.js";
@@ -26,6 +26,8 @@
26
26
  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
27
  */
28
28
 
29
+ import "./core/codec-worker-web.js";
30
+
29
31
  export {
30
32
  ZipWriter,
31
33
  ZipWriterStream,
@@ -50,5 +52,7 @@ export {
50
52
  ERR_INVALID_UNIX_ID_SIZE,
51
53
  ERR_INVALID_MSDOS_ATTRIBUTES,
52
54
  ERR_INVALID_MSDOS_DATA,
55
+ ERR_INVALID_LEVEL,
56
+ ERR_INVALID_PASSWORD_TYPE,
53
57
  ERR_UNSUPPORTED_CRYPTO_API
54
58
  } from "./core/zip-writer.js";
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A JavaScript library to zip and unzip files in the browser, Deno and Node.js",
4
4
  "author": "Gildas Lormeau",
5
5
  "license": "BSD-3-Clause",
6
- "version": "2.8.49",
6
+ "version": "2.8.51",
7
7
  "type": "module",
8
8
  "keywords": [
9
9
  "zip",