@zip.js/zip.js 2.7.69 → 2.7.71

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.
@@ -33,6 +33,7 @@ import {
33
33
  CODEC_INFLATE,
34
34
  CODEC_DEFLATE,
35
35
  ERR_INVALID_SIGNATURE,
36
+ ERR_INVALID_UNCOMPRESSED_SIZE,
36
37
  ERR_INVALID_PASSWORD,
37
38
  ERR_ABORT_CHECK_PASSWORD
38
39
  } from "./streams/codec-stream.js";
@@ -47,6 +48,7 @@ export {
47
48
  CODEC_DEFLATE,
48
49
  CODEC_INFLATE,
49
50
  ERR_INVALID_SIGNATURE,
51
+ ERR_INVALID_UNCOMPRESSED_SIZE,
50
52
  ERR_INVALID_PASSWORD,
51
53
  ERR_ABORT_CHECK_PASSWORD
52
54
  };
@@ -45,6 +45,10 @@ const ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH = 20;
45
45
  const ZIP64_END_OF_CENTRAL_DIR_LENGTH = 56;
46
46
  const ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH = END_OF_CENTRAL_DIR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH + ZIP64_END_OF_CENTRAL_DIR_LENGTH;
47
47
 
48
+ const DATA_DESCRIPTOR_RECORD_LENGTH = 12;
49
+ const DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH = 20;
50
+ const DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH = 4;
51
+
48
52
  const EXTRAFIELD_TYPE_ZIP64 = 0x0001;
49
53
  const EXTRAFIELD_TYPE_AES = 0x9901;
50
54
  const EXTRAFIELD_TYPE_NTFS = 0x000a;
@@ -73,7 +77,7 @@ const VERSION_AES = 0x33;
73
77
 
74
78
  const DIRECTORY_SIGNATURE = "/";
75
79
 
76
- const HEADER_SIZE = 26;
80
+ const HEADER_SIZE = 30;
77
81
  const HEADER_OFFSET_SIGNATURE = 10;
78
82
  const HEADER_OFFSET_COMPRESSED_SIZE = 14;
79
83
  const HEADER_OFFSET_UNCOMPRESSED_SIZE = 18;
@@ -99,6 +103,9 @@ export {
99
103
  END_OF_CENTRAL_DIR_SIGNATURE,
100
104
  ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE,
101
105
  ZIP64_END_OF_CENTRAL_DIR_SIGNATURE,
106
+ DATA_DESCRIPTOR_RECORD_LENGTH,
107
+ DATA_DESCRIPTOR_RECORD_ZIP_64_LENGTH,
108
+ DATA_DESCRIPTOR_RECORD_SIGNATURE_LENGTH,
102
109
  EXTRAFIELD_TYPE_ZIP64,
103
110
  EXTRAFIELD_TYPE_AES,
104
111
  EXTRAFIELD_TYPE_NTFS,
package/lib/core/io.js CHANGED
@@ -176,10 +176,12 @@ class Data64URIWriter extends Writer {
176
176
  for (; indexArray < array.length; indexArray++) {
177
177
  writer.pending += String.fromCharCode(array[indexArray]);
178
178
  }
179
- if (dataString.length > 2) {
180
- writer.data += btoa(dataString);
181
- } else {
182
- writer.pending = dataString;
179
+ if (dataString.length) {
180
+ if (dataString.length > 2) {
181
+ writer.data += btoa(dataString);
182
+ } else {
183
+ writer.pending += dataString;
184
+ }
183
185
  }
184
186
  }
185
187
 
@@ -0,0 +1,89 @@
1
+ /*
2
+ Copyright (c) 2022 Gildas Lormeau. All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in
12
+ the documentation and/or other materials provided with the distribution.
13
+
14
+ 3. The names of the authors may not be used to endorse or promote products
15
+ derived from this software without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
18
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JCRAFT,
20
+ INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
21
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
+ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+ */
28
+
29
+ const OPTION_FILENAME_ENCODING = "filenameEncoding";
30
+ const OPTION_COMMENT_ENCODING = "commentEncoding";
31
+ const OPTION_DECODE_TEXT = "decodeText";
32
+ const OPTION_EXTRACT_PREPENDED_DATA = "extractPrependedData";
33
+ const OPTION_EXTRACT_APPENDED_DATA = "extractAppendedData";
34
+ const OPTION_PASSWORD = "password";
35
+ const OPTION_RAW_PASSWORD = "rawPassword";
36
+ const OPTION_PASS_THROUGH = "passThrough";
37
+ const OPTION_SIGNAL = "signal";
38
+ const OPTION_CHECK_PASSWORD_ONLY = "checkPasswordOnly";
39
+ const OPTION_CHECK_OVERLAPPING_ENTRY_ONLY = "checkOverlappingEntryOnly";
40
+ const OPTION_CHECK_OVERLAPPING_ENTRY = "checkOverlappingEntry";
41
+ const OPTION_CHECK_SIGNATURE = "checkSignature";
42
+ const OPTION_USE_WEB_WORKERS = "useWebWorkers";
43
+ const OPTION_USE_COMPRESSION_STREAM = "useCompressionStream";
44
+ const OPTION_TRANSFER_STREAMS = "transferStreams";
45
+ const OPTION_PREVENT_CLOSE = "preventClose";
46
+ const OPTION_ENCRYPTION_STRENGTH = "encryptionStrength";
47
+ const OPTION_EXTENDED_TIMESTAMP = "extendedTimestamp";
48
+ const OPTION_KEEP_ORDER = "keepOrder";
49
+ const OPTION_LEVEL = "level";
50
+ const OPTION_BUFFERED_WRITE = "bufferedWrite";
51
+ const OPTION_DATA_DESCRIPTOR_SIGNATURE = "dataDescriptorSignature";
52
+ const OPTION_USE_UNICODE_FILE_NAMES = "useUnicodeFileNames";
53
+ const OPTION_DATA_DESCRIPTOR = "dataDescriptor";
54
+ const OPTION_SUPPORT_ZIP64_SPLIT_FILE = "supportZip64SplitFile";
55
+ const OPTION_ENCODE_TEXT = "encodeText";
56
+ const OPTION_OFFSET = "offset";
57
+ const OPTION_USDZ = "usdz";
58
+
59
+ export {
60
+ OPTION_FILENAME_ENCODING,
61
+ OPTION_COMMENT_ENCODING,
62
+ OPTION_DECODE_TEXT,
63
+ OPTION_EXTRACT_PREPENDED_DATA,
64
+ OPTION_EXTRACT_APPENDED_DATA,
65
+ OPTION_PASSWORD,
66
+ OPTION_RAW_PASSWORD,
67
+ OPTION_PASS_THROUGH,
68
+ OPTION_SIGNAL,
69
+ OPTION_CHECK_PASSWORD_ONLY,
70
+ OPTION_CHECK_OVERLAPPING_ENTRY_ONLY,
71
+ OPTION_CHECK_OVERLAPPING_ENTRY,
72
+ OPTION_CHECK_SIGNATURE,
73
+ OPTION_USE_WEB_WORKERS,
74
+ OPTION_USE_COMPRESSION_STREAM,
75
+ OPTION_TRANSFER_STREAMS,
76
+ OPTION_PREVENT_CLOSE,
77
+ OPTION_ENCRYPTION_STRENGTH,
78
+ OPTION_EXTENDED_TIMESTAMP,
79
+ OPTION_KEEP_ORDER,
80
+ OPTION_LEVEL,
81
+ OPTION_BUFFERED_WRITE,
82
+ OPTION_DATA_DESCRIPTOR_SIGNATURE,
83
+ OPTION_USE_UNICODE_FILE_NAMES,
84
+ OPTION_DATA_DESCRIPTOR,
85
+ OPTION_SUPPORT_ZIP64_SPLIT_FILE,
86
+ OPTION_ENCODE_TEXT,
87
+ OPTION_OFFSET,
88
+ OPTION_USDZ
89
+ };
@@ -39,6 +39,7 @@
39
39
  import {
40
40
  ERR_INVALID_PASSWORD,
41
41
  ERR_INVALID_SIGNATURE,
42
+ ERR_INVALID_UNCOMPRESSED_SIZE,
42
43
  ERR_ABORT_CHECK_PASSWORD,
43
44
  InflateStream,
44
45
  DeflateStream
@@ -64,6 +65,7 @@ export {
64
65
  MESSAGE_CLOSE,
65
66
  ERR_INVALID_PASSWORD,
66
67
  ERR_INVALID_SIGNATURE,
68
+ ERR_INVALID_UNCOMPRESSED_SIZE,
67
69
  ERR_ABORT_CHECK_PASSWORD,
68
70
  CodecStream,
69
71
  ChunkStream
@@ -103,6 +105,9 @@ class CodecStream extends TransformStream {
103
105
  if (chunk && chunk.length) {
104
106
  controller.enqueue(chunk);
105
107
  codec.outputSize += chunk.length;
108
+ if (options.outputSize && codec.outputSize > options.outputSize) {
109
+ throw new Error(ERR_INVALID_UNCOMPRESSED_SIZE);
110
+ }
106
111
  }
107
112
  },
108
113
  flush() {
@@ -131,7 +131,7 @@ function createKeys(target, password) {
131
131
  Object.assign(target, {
132
132
  keys,
133
133
  crcKey0: new Crc32(keys[0]),
134
- crcKey2: new Crc32(keys[2]),
134
+ crcKey2: new Crc32(keys[2])
135
135
  });
136
136
  for (let index = 0; index < password.length; index++) {
137
137
  updateKeys(target, password.charCodeAt(index));
@@ -44,6 +44,7 @@ import {
44
44
  ERR_ABORT_CHECK_PASSWORD
45
45
  } from "./common-crypto.js";
46
46
 
47
+ const ERR_INVALID_UNCOMPRESSED_SIZE = "Invalid uncompressed size";
47
48
  const COMPRESSION_FORMAT = "deflate-raw";
48
49
 
49
50
  class DeflateStream extends TransformStream {
@@ -53,7 +54,7 @@ class DeflateStream extends TransformStream {
53
54
  const { compressed, encrypted, useCompressionStream, zipCrypto, signed, level } = options;
54
55
  const stream = this;
55
56
  let crc32Stream, encryptionStream;
56
- let readable = filterEmptyChunks(super.readable);
57
+ let readable = super.readable;
57
58
  if ((!encrypted || zipCrypto) && signed) {
58
59
  crc32Stream = new Crc32Stream();
59
60
  readable = pipeThrough(readable, crc32Stream);
@@ -88,7 +89,7 @@ class InflateStream extends TransformStream {
88
89
  super({});
89
90
  const { zipCrypto, encrypted, signed, signature, compressed, useCompressionStream } = options;
90
91
  let crc32Stream, decryptionStream;
91
- let readable = filterEmptyChunks(super.readable);
92
+ let readable = super.readable;
92
93
  if (encrypted) {
93
94
  if (zipCrypto) {
94
95
  readable = pipeThrough(readable, new ZipCryptoDecryptionStream(options));
@@ -120,19 +121,10 @@ export {
120
121
  InflateStream,
121
122
  ERR_INVALID_PASSWORD,
122
123
  ERR_INVALID_SIGNATURE,
124
+ ERR_INVALID_UNCOMPRESSED_SIZE,
123
125
  ERR_ABORT_CHECK_PASSWORD
124
126
  };
125
127
 
126
- function filterEmptyChunks(readable) {
127
- return pipeThrough(readable, new TransformStream({
128
- transform(chunk, controller) {
129
- if (chunk && chunk.length) {
130
- controller.enqueue(chunk);
131
- }
132
- }
133
- }));
134
- }
135
-
136
128
  function setReadable(stream, readable, flush) {
137
129
  readable = pipeThrough(readable, new TransformStream({ flush }));
138
130
  Object.defineProperty(stream, "readable", {
@@ -142,24 +134,9 @@ function setReadable(stream, readable, flush) {
142
134
  });
143
135
  }
144
136
 
145
- function pipeThroughCommpressionStream(readable, useCompressionStream, options, CodecStreamNative, CodecStream) {
146
- try {
147
- const CompressionStream = useCompressionStream && CodecStreamNative ? CodecStreamNative : CodecStream;
148
- readable = pipeThrough(readable, new CompressionStream(COMPRESSION_FORMAT, options));
149
- // eslint-disable-next-line no-unused-vars
150
- } catch (_) {
151
- if (useCompressionStream) {
152
- try {
153
- readable = pipeThrough(readable, new CodecStream(COMPRESSION_FORMAT, options));
154
- // eslint-disable-next-line no-unused-vars
155
- } catch (_) {
156
- return readable;
157
- }
158
- } else {
159
- return readable;
160
- }
161
- }
162
- return readable;
137
+ function pipeThroughCommpressionStream(readable, useCompressionStream, options, CompressionStreamNative, CompressionStreamJS) {
138
+ const CompressionStream = useCompressionStream && CompressionStreamNative ? CompressionStreamNative : CompressionStreamJS;
139
+ return pipeThrough(readable, new CompressionStream(COMPRESSION_FORMAT, options));
163
140
  }
164
141
 
165
142
  function pipeThrough(readable, transformStream) {
@@ -30,8 +30,8 @@ const PROPERTY_NAME_FILENAME = "filename";
30
30
  const PROPERTY_NAME_RAW_FILENAME = "rawFilename";
31
31
  const PROPERTY_NAME_COMMENT = "comment";
32
32
  const PROPERTY_NAME_RAW_COMMENT = "rawComment";
33
- const PROPERTY_NAME_UNCOMPPRESSED_SIZE = "uncompressedSize";
34
- const PROPERTY_NAME_COMPPRESSED_SIZE = "compressedSize";
33
+ const PROPERTY_NAME_UNCOMPRESSED_SIZE = "uncompressedSize";
34
+ const PROPERTY_NAME_COMPRESSED_SIZE = "compressedSize";
35
35
  const PROPERTY_NAME_OFFSET = "offset";
36
36
  const PROPERTY_NAME_DISK_NUMBER_START = "diskNumberStart";
37
37
  const PROPERTY_NAME_LAST_MODIFICATION_DATE = "lastModDate";
@@ -52,12 +52,20 @@ const PROPERTY_NAME_VERSION_MADE_BY = "versionMadeBy";
52
52
  const PROPERTY_NAME_ZIPCRYPTO = "zipCrypto";
53
53
  const PROPERTY_NAME_DIRECTORY = "directory";
54
54
  const PROPERTY_NAME_EXECUTABLE = "executable";
55
+ const PROPERTY_NAME_COMPRESSION_METHOD = "compressionMethod";
56
+ const PROPERTY_NAME_SIGNATURE = "signature";
57
+ const PROPERTY_NAME_EXTRA_FIELD = "extraField";
55
58
 
56
59
  const PROPERTY_NAMES = [
57
- PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPPRESSED_SIZE, PROPERTY_NAME_UNCOMPPRESSED_SIZE,
60
+ PROPERTY_NAME_FILENAME, PROPERTY_NAME_RAW_FILENAME, PROPERTY_NAME_COMPRESSED_SIZE, PROPERTY_NAME_UNCOMPRESSED_SIZE,
58
61
  PROPERTY_NAME_LAST_MODIFICATION_DATE, PROPERTY_NAME_RAW_LAST_MODIFICATION_DATE, PROPERTY_NAME_COMMENT, PROPERTY_NAME_RAW_COMMENT,
59
62
  PROPERTY_NAME_LAST_ACCESS_DATE, PROPERTY_NAME_CREATION_DATE, PROPERTY_NAME_OFFSET, PROPERTY_NAME_DISK_NUMBER_START,
60
- PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64, PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY, PROPERTY_NAME_ZIPCRYPTO, PROPERTY_NAME_DIRECTORY, PROPERTY_NAME_EXECUTABLE, "bitFlag", "signature", "filenameUTF8", "commentUTF8", "compressionMethod", "extraField", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment", "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
63
+ PROPERTY_NAME_DISK_NUMBER_START, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_INTERNAL_FILE_ATTRIBUTES,
64
+ PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTE, PROPERTY_NAME_EXTERNAL_FILE_ATTRIBUTES, PROPERTY_NAME_MS_DOS_COMPATIBLE, PROPERTY_NAME_ZIP64,
65
+ PROPERTY_NAME_ENCRYPTED, PROPERTY_NAME_VERSION, PROPERTY_NAME_VERSION_MADE_BY, PROPERTY_NAME_ZIPCRYPTO, PROPERTY_NAME_DIRECTORY,
66
+ PROPERTY_NAME_EXECUTABLE, PROPERTY_NAME_COMPRESSION_METHOD, PROPERTY_NAME_SIGNATURE, PROPERTY_NAME_EXTRA_FIELD,
67
+ "bitFlag", "filenameUTF8", "commentUTF8", "rawExtraField", "extraFieldZip64", "extraFieldUnicodePath", "extraFieldUnicodeComment",
68
+ "extraFieldAES", "extraFieldNTFS", "extraFieldExtendedTimestamp"];
61
69
 
62
70
  class Entry {
63
71
 
@@ -72,8 +80,8 @@ export {
72
80
  PROPERTY_NAME_RAW_FILENAME,
73
81
  PROPERTY_NAME_COMMENT,
74
82
  PROPERTY_NAME_RAW_COMMENT,
75
- PROPERTY_NAME_UNCOMPPRESSED_SIZE,
76
- PROPERTY_NAME_COMPPRESSED_SIZE,
83
+ PROPERTY_NAME_UNCOMPRESSED_SIZE,
84
+ PROPERTY_NAME_COMPRESSED_SIZE,
77
85
  PROPERTY_NAME_OFFSET,
78
86
  PROPERTY_NAME_DISK_NUMBER_START,
79
87
  PROPERTY_NAME_LAST_MODIFICATION_DATE,
@@ -94,5 +102,8 @@ export {
94
102
  PROPERTY_NAME_ZIPCRYPTO,
95
103
  PROPERTY_NAME_DIRECTORY,
96
104
  PROPERTY_NAME_EXECUTABLE,
105
+ PROPERTY_NAME_COMPRESSION_METHOD,
106
+ PROPERTY_NAME_SIGNATURE,
107
+ PROPERTY_NAME_EXTRA_FIELD,
97
108
  Entry
98
109
  };
@@ -874,7 +874,7 @@ async function transformToFileSystemhandles(entry) {
874
874
  next() {
875
875
  const result = {
876
876
  value: entries[entryIndex],
877
- done: entryIndex === entries.length
877
+ done: entryIndex == entries.length
878
878
  };
879
879
  entryIndex++;
880
880
  return result;