stage-browser 0.0.0-stage → 0.1.1
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/README.md +136 -2
- package/build/icon.icns +0 -0
- package/build/icon.png +0 -0
- package/dist/bin/stage.js +111 -0
- package/dist/main/cli-args.js +28 -0
- package/dist/main/context-menu.js +68 -0
- package/dist/main/context.js +2 -0
- package/dist/main/extensions.js +78 -0
- package/dist/main/ipc.js +90 -0
- package/dist/main/main.js +279 -0
- package/dist/main/menu.js +140 -0
- package/dist/main/reveal.js +155 -0
- package/dist/main/selftest.js +490 -0
- package/dist/main/store.js +85 -0
- package/dist/main/suggest.js +43 -0
- package/dist/main/tabs.js +324 -0
- package/dist/main/url.js +38 -0
- package/dist/main/window.js +68 -0
- package/dist/preload/extension-compat.js +163 -0
- package/dist/preload/ui-preload.js +33 -0
- package/dist/shared/contract.js +6 -0
- package/dist/ui/app.js +653 -0
- package/dist/ui/index.html +41 -0
- package/dist/ui/mock.js +479 -0
- package/dist/ui/newtab.html +69 -0
- package/dist/ui/styles.css +410 -0
- package/node_modules/@types/chrome/LICENSE +21 -0
- package/node_modules/@types/chrome/README.md +15 -0
- package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
- package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
- package/node_modules/@types/chrome/index.d.ts +13786 -0
- package/node_modules/@types/chrome/package.json +99 -0
- package/node_modules/@types/filesystem/LICENSE +21 -0
- package/node_modules/@types/filesystem/README.md +15 -0
- package/node_modules/@types/filesystem/index.d.ts +564 -0
- package/node_modules/@types/filesystem/package.json +26 -0
- package/node_modules/@types/filewriter/LICENSE +21 -0
- package/node_modules/@types/filewriter/README.md +15 -0
- package/node_modules/@types/filewriter/index.d.ts +166 -0
- package/node_modules/@types/filewriter/package.json +25 -0
- package/node_modules/@types/har-format/LICENSE +21 -0
- package/node_modules/@types/har-format/README.md +15 -0
- package/node_modules/@types/har-format/index.d.ts +938 -0
- package/node_modules/@types/har-format/package.json +31 -0
- package/node_modules/adm-zip/LICENSE +21 -0
- package/node_modules/adm-zip/README.md +90 -0
- package/node_modules/adm-zip/adm-zip.js +1020 -0
- package/node_modules/adm-zip/headers/entryHeader.js +396 -0
- package/node_modules/adm-zip/headers/index.js +2 -0
- package/node_modules/adm-zip/headers/mainHeader.js +177 -0
- package/node_modules/adm-zip/methods/deflater.js +33 -0
- package/node_modules/adm-zip/methods/index.js +3 -0
- package/node_modules/adm-zip/methods/inflater.js +64 -0
- package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
- package/node_modules/adm-zip/package.json +56 -0
- package/node_modules/adm-zip/types.d.ts +223 -0
- package/node_modules/adm-zip/util/constants.js +142 -0
- package/node_modules/adm-zip/util/decoder.js +5 -0
- package/node_modules/adm-zip/util/errors.js +66 -0
- package/node_modules/adm-zip/util/fattr.js +76 -0
- package/node_modules/adm-zip/util/index.js +5 -0
- package/node_modules/adm-zip/util/utils.js +481 -0
- package/node_modules/adm-zip/zipEntry.js +415 -0
- package/node_modules/adm-zip/zipFile.js +466 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/electron-chrome-web-store/README.md +143 -0
- package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
- package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
- package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
- package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
- package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
- package/node_modules/electron-chrome-web-store/package.json +43 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/pbf/LICENSE +27 -0
- package/node_modules/pbf/README.md +293 -0
- package/node_modules/pbf/bin/pbf +17 -0
- package/node_modules/pbf/compile.js +441 -0
- package/node_modules/pbf/dist/pbf-dev.js +838 -0
- package/node_modules/pbf/dist/pbf.js +1 -0
- package/node_modules/pbf/index.d.ts +206 -0
- package/node_modules/pbf/index.js +830 -0
- package/node_modules/pbf/package.json +63 -0
- package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
- package/node_modules/protocol-buffers-schema/LICENSE +21 -0
- package/node_modules/protocol-buffers-schema/README.md +122 -0
- package/node_modules/protocol-buffers-schema/example.js +11 -0
- package/node_modules/protocol-buffers-schema/example.proto +13 -0
- package/node_modules/protocol-buffers-schema/index.js +6 -0
- package/node_modules/protocol-buffers-schema/package.json +31 -0
- package/node_modules/protocol-buffers-schema/parse.js +769 -0
- package/node_modules/protocol-buffers-schema/stringify.js +206 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
- package/node_modules/protocol-buffers-schema/test/index.js +157 -0
- package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
- package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
- package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
- package/node_modules/resolve-protobuf-schema/README.md +49 -0
- package/node_modules/resolve-protobuf-schema/index.js +50 -0
- package/node_modules/resolve-protobuf-schema/package.json +25 -0
- package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
- package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
- package/package.json +64 -4
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
var Utils = require("../util"),
|
|
2
|
+
Constants = Utils.Constants;
|
|
3
|
+
|
|
4
|
+
/* The central directory file header */
|
|
5
|
+
module.exports = function () {
|
|
6
|
+
var _verMade = 20, // v2.0
|
|
7
|
+
_version = 10, // v1.0
|
|
8
|
+
_flags = 0,
|
|
9
|
+
_method = 0,
|
|
10
|
+
_time = 0,
|
|
11
|
+
_crc = 0,
|
|
12
|
+
_compressedSize = 0,
|
|
13
|
+
_size = 0,
|
|
14
|
+
_fnameLen = 0,
|
|
15
|
+
_extraLen = 0,
|
|
16
|
+
_comLen = 0,
|
|
17
|
+
_diskStart = 0,
|
|
18
|
+
_inattr = 0,
|
|
19
|
+
_attr = 0,
|
|
20
|
+
_offset = 0;
|
|
21
|
+
|
|
22
|
+
_verMade |= Utils.isWin ? 0x0a00 : 0x0300;
|
|
23
|
+
|
|
24
|
+
// Set EFS flag since filename and comment fields are all by default encoded using UTF-8.
|
|
25
|
+
// Without it file names may be corrupted for other apps when file names use unicode chars
|
|
26
|
+
_flags |= Constants.FLG_EFS;
|
|
27
|
+
|
|
28
|
+
const _localHeader = {
|
|
29
|
+
extraLen: 0
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// casting
|
|
33
|
+
const uint32 = (val) => Math.max(0, val) >>> 0;
|
|
34
|
+
const uint16 = (val) => Math.max(0, val) & 0xffff;
|
|
35
|
+
const uint8 = (val) => Math.max(0, val) & 0xff;
|
|
36
|
+
|
|
37
|
+
_time = Utils.fromDate2DOS(new Date());
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
get made() {
|
|
41
|
+
return _verMade;
|
|
42
|
+
},
|
|
43
|
+
set made(val) {
|
|
44
|
+
_verMade = val;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
get version() {
|
|
48
|
+
return _version;
|
|
49
|
+
},
|
|
50
|
+
set version(val) {
|
|
51
|
+
_version = val;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
get flags() {
|
|
55
|
+
return _flags;
|
|
56
|
+
},
|
|
57
|
+
set flags(val) {
|
|
58
|
+
_flags = val;
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
get flags_efs() {
|
|
62
|
+
return (_flags & Constants.FLG_EFS) > 0;
|
|
63
|
+
},
|
|
64
|
+
set flags_efs(val) {
|
|
65
|
+
if (val) {
|
|
66
|
+
_flags |= Constants.FLG_EFS;
|
|
67
|
+
} else {
|
|
68
|
+
_flags &= ~Constants.FLG_EFS;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
get flags_desc() {
|
|
73
|
+
return (_flags & Constants.FLG_DESC) > 0;
|
|
74
|
+
},
|
|
75
|
+
set flags_desc(val) {
|
|
76
|
+
if (val) {
|
|
77
|
+
_flags |= Constants.FLG_DESC;
|
|
78
|
+
} else {
|
|
79
|
+
_flags &= ~Constants.FLG_DESC;
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
get method() {
|
|
84
|
+
return _method;
|
|
85
|
+
},
|
|
86
|
+
set method(val) {
|
|
87
|
+
switch (val) {
|
|
88
|
+
case Constants.STORED:
|
|
89
|
+
this.version = 10;
|
|
90
|
+
break;
|
|
91
|
+
case Constants.DEFLATED:
|
|
92
|
+
default:
|
|
93
|
+
this.version = 20;
|
|
94
|
+
}
|
|
95
|
+
_method = val;
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
get time() {
|
|
99
|
+
return Utils.fromDOS2Date(this.timeval);
|
|
100
|
+
},
|
|
101
|
+
set time(val) {
|
|
102
|
+
val = new Date(val);
|
|
103
|
+
this.timeval = Utils.fromDate2DOS(val);
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
get timeval() {
|
|
107
|
+
return _time;
|
|
108
|
+
},
|
|
109
|
+
set timeval(val) {
|
|
110
|
+
_time = uint32(val);
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
get timeHighByte() {
|
|
114
|
+
return uint8(_time >>> 8);
|
|
115
|
+
},
|
|
116
|
+
get crc() {
|
|
117
|
+
return _crc;
|
|
118
|
+
},
|
|
119
|
+
set crc(val) {
|
|
120
|
+
_crc = uint32(val);
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
get compressedSize() {
|
|
124
|
+
return _compressedSize;
|
|
125
|
+
},
|
|
126
|
+
set compressedSize(val) {
|
|
127
|
+
_compressedSize = uint32(val);
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
get size() {
|
|
131
|
+
return _size;
|
|
132
|
+
},
|
|
133
|
+
set size(val) {
|
|
134
|
+
_size = uint32(val);
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
get fileNameLength() {
|
|
138
|
+
return _fnameLen;
|
|
139
|
+
},
|
|
140
|
+
set fileNameLength(val) {
|
|
141
|
+
_fnameLen = val;
|
|
142
|
+
},
|
|
143
|
+
|
|
144
|
+
get extraLength() {
|
|
145
|
+
return _extraLen;
|
|
146
|
+
},
|
|
147
|
+
set extraLength(val) {
|
|
148
|
+
_extraLen = val;
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
get extraLocalLength() {
|
|
152
|
+
return _localHeader.extraLen;
|
|
153
|
+
},
|
|
154
|
+
set extraLocalLength(val) {
|
|
155
|
+
_localHeader.extraLen = val;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
get commentLength() {
|
|
159
|
+
return _comLen;
|
|
160
|
+
},
|
|
161
|
+
set commentLength(val) {
|
|
162
|
+
_comLen = val;
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
get diskNumStart() {
|
|
166
|
+
return _diskStart;
|
|
167
|
+
},
|
|
168
|
+
set diskNumStart(val) {
|
|
169
|
+
_diskStart = uint32(val);
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
get inAttr() {
|
|
173
|
+
return _inattr;
|
|
174
|
+
},
|
|
175
|
+
set inAttr(val) {
|
|
176
|
+
_inattr = uint32(val);
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
get attr() {
|
|
180
|
+
return _attr;
|
|
181
|
+
},
|
|
182
|
+
set attr(val) {
|
|
183
|
+
_attr = uint32(val);
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
// get Unix file permissions
|
|
187
|
+
get fileAttr() {
|
|
188
|
+
// Mask to the 9 rwxrwxrwx bits only. The setuid (0o4000), setgid
|
|
189
|
+
// (0o2000) and sticky (0o1000) bits are attacker-controlled archive
|
|
190
|
+
// metadata; preserving them on extraction (keepOriginalPermission)
|
|
191
|
+
// lets a crafted zip plant a setuid-root binary when extracting as
|
|
192
|
+
// root, a local privilege escalation (GHSA-679w-jf3m-wh39).
|
|
193
|
+
return ((_attr || 0) >> 16) & 0o777;
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
get offset() {
|
|
197
|
+
return _offset;
|
|
198
|
+
},
|
|
199
|
+
set offset(val) {
|
|
200
|
+
_offset = uint32(val);
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
get encrypted() {
|
|
204
|
+
return (_flags & Constants.FLG_ENC) === Constants.FLG_ENC;
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
get centralHeaderSize() {
|
|
208
|
+
return Constants.CENHDR + _fnameLen + _extraLen + _comLen;
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
get realDataOffset() {
|
|
212
|
+
return _offset + Constants.LOCHDR + _localHeader.fnameLen + _localHeader.extraLen;
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
get localHeader() {
|
|
216
|
+
return _localHeader;
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
loadLocalHeaderFromBinary: function (/*Buffer*/ input) {
|
|
220
|
+
// The LOC offset comes from the central directory and is attacker
|
|
221
|
+
// controlled. Reject one that would read past the end of the buffer,
|
|
222
|
+
// otherwise readUInt32LE below throws a raw RangeError instead of a
|
|
223
|
+
// clean INVALID_LOC (and escapes the async error path).
|
|
224
|
+
if (_offset < 0 || _offset + Constants.LOCHDR > input.length) {
|
|
225
|
+
throw Utils.Errors.INVALID_LOC();
|
|
226
|
+
}
|
|
227
|
+
var data = input.slice(_offset, _offset + Constants.LOCHDR);
|
|
228
|
+
// 30 bytes and should start with "PK\003\004"
|
|
229
|
+
if (data.readUInt32LE(0) !== Constants.LOCSIG) {
|
|
230
|
+
throw Utils.Errors.INVALID_LOC();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// version needed to extract
|
|
234
|
+
_localHeader.version = data.readUInt16LE(Constants.LOCVER);
|
|
235
|
+
// general purpose bit flag
|
|
236
|
+
_localHeader.flags = data.readUInt16LE(Constants.LOCFLG);
|
|
237
|
+
// desc flag
|
|
238
|
+
_localHeader.flags_desc = (_localHeader.flags & Constants.FLG_DESC) > 0;
|
|
239
|
+
// compression method
|
|
240
|
+
_localHeader.method = data.readUInt16LE(Constants.LOCHOW);
|
|
241
|
+
// modification time (2 bytes time, 2 bytes date)
|
|
242
|
+
_localHeader.time = data.readUInt32LE(Constants.LOCTIM);
|
|
243
|
+
// uncompressed file crc-32 valu
|
|
244
|
+
_localHeader.crc = data.readUInt32LE(Constants.LOCCRC);
|
|
245
|
+
// compressed size
|
|
246
|
+
_localHeader.compressedSize = data.readUInt32LE(Constants.LOCSIZ);
|
|
247
|
+
// uncompressed size
|
|
248
|
+
_localHeader.size = data.readUInt32LE(Constants.LOCLEN);
|
|
249
|
+
// filename length
|
|
250
|
+
_localHeader.fnameLen = data.readUInt16LE(Constants.LOCNAM);
|
|
251
|
+
// extra field length
|
|
252
|
+
_localHeader.extraLen = data.readUInt16LE(Constants.LOCEXT);
|
|
253
|
+
|
|
254
|
+
// read extra data
|
|
255
|
+
const extraStart = _offset + Constants.LOCHDR + _localHeader.fnameLen;
|
|
256
|
+
const extraEnd = extraStart + _localHeader.extraLen;
|
|
257
|
+
return input.slice(extraStart, extraEnd);
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
loadFromBinary: function (/*Buffer*/ data) {
|
|
261
|
+
// data should be 46 bytes and start with "PK 01 02"
|
|
262
|
+
if (data.length !== Constants.CENHDR || data.readUInt32LE(0) !== Constants.CENSIG) {
|
|
263
|
+
throw Utils.Errors.INVALID_CEN();
|
|
264
|
+
}
|
|
265
|
+
// version made by
|
|
266
|
+
_verMade = data.readUInt16LE(Constants.CENVEM);
|
|
267
|
+
// version needed to extract
|
|
268
|
+
_version = data.readUInt16LE(Constants.CENVER);
|
|
269
|
+
// encrypt, decrypt flags
|
|
270
|
+
_flags = data.readUInt16LE(Constants.CENFLG);
|
|
271
|
+
// compression method
|
|
272
|
+
_method = data.readUInt16LE(Constants.CENHOW);
|
|
273
|
+
// modification time (2 bytes time, 2 bytes date)
|
|
274
|
+
_time = data.readUInt32LE(Constants.CENTIM);
|
|
275
|
+
// uncompressed file crc-32 value
|
|
276
|
+
_crc = data.readUInt32LE(Constants.CENCRC);
|
|
277
|
+
// compressed size
|
|
278
|
+
_compressedSize = data.readUInt32LE(Constants.CENSIZ);
|
|
279
|
+
// uncompressed size
|
|
280
|
+
_size = data.readUInt32LE(Constants.CENLEN);
|
|
281
|
+
// filename length
|
|
282
|
+
_fnameLen = data.readUInt16LE(Constants.CENNAM);
|
|
283
|
+
// extra field length
|
|
284
|
+
_extraLen = data.readUInt16LE(Constants.CENEXT);
|
|
285
|
+
// file comment length
|
|
286
|
+
_comLen = data.readUInt16LE(Constants.CENCOM);
|
|
287
|
+
// volume number start
|
|
288
|
+
_diskStart = data.readUInt16LE(Constants.CENDSK);
|
|
289
|
+
// internal file attributes
|
|
290
|
+
_inattr = data.readUInt16LE(Constants.CENATT);
|
|
291
|
+
// external file attributes
|
|
292
|
+
_attr = data.readUInt32LE(Constants.CENATX);
|
|
293
|
+
// LOC header offset
|
|
294
|
+
_offset = data.readUInt32LE(Constants.CENOFF);
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
localHeaderToBinary: function () {
|
|
298
|
+
// LOC header size (30 bytes)
|
|
299
|
+
var data = Buffer.alloc(Constants.LOCHDR);
|
|
300
|
+
// "PK\003\004"
|
|
301
|
+
data.writeUInt32LE(Constants.LOCSIG, 0);
|
|
302
|
+
// version needed to extract
|
|
303
|
+
data.writeUInt16LE(_version, Constants.LOCVER);
|
|
304
|
+
// general purpose bit flag
|
|
305
|
+
// clear bit 3 (data descriptor): we always write the real crc-32
|
|
306
|
+
// and sizes into this local header, so no trailing descriptor is
|
|
307
|
+
// emitted. Leaving the flag set would make the output unreadable
|
|
308
|
+
// (see issue #555).
|
|
309
|
+
data.writeUInt16LE(_flags & ~Constants.FLG_DESC, Constants.LOCFLG);
|
|
310
|
+
// compression method
|
|
311
|
+
data.writeUInt16LE(_method, Constants.LOCHOW);
|
|
312
|
+
// modification time (2 bytes time, 2 bytes date)
|
|
313
|
+
data.writeUInt32LE(_time, Constants.LOCTIM);
|
|
314
|
+
// uncompressed file crc-32 value
|
|
315
|
+
data.writeUInt32LE(_crc, Constants.LOCCRC);
|
|
316
|
+
// compressed size
|
|
317
|
+
data.writeUInt32LE(_compressedSize, Constants.LOCSIZ);
|
|
318
|
+
// uncompressed size
|
|
319
|
+
data.writeUInt32LE(_size, Constants.LOCLEN);
|
|
320
|
+
// filename length
|
|
321
|
+
data.writeUInt16LE(_fnameLen, Constants.LOCNAM);
|
|
322
|
+
// extra field length
|
|
323
|
+
data.writeUInt16LE(_localHeader.extraLen, Constants.LOCEXT);
|
|
324
|
+
return data;
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
centralHeaderToBinary: function () {
|
|
328
|
+
// CEN header size (46 bytes)
|
|
329
|
+
var data = Buffer.alloc(Constants.CENHDR + _fnameLen + _extraLen + _comLen);
|
|
330
|
+
// "PK\001\002"
|
|
331
|
+
data.writeUInt32LE(Constants.CENSIG, 0);
|
|
332
|
+
// version made by
|
|
333
|
+
data.writeUInt16LE(_verMade, Constants.CENVEM);
|
|
334
|
+
// version needed to extract
|
|
335
|
+
data.writeUInt16LE(_version, Constants.CENVER);
|
|
336
|
+
// encrypt, decrypt flags
|
|
337
|
+
// clear bit 3 (data descriptor) to match the local header we emit
|
|
338
|
+
// (real crc/sizes are written, no descriptor follows the data) — issue #555
|
|
339
|
+
data.writeUInt16LE(_flags & ~Constants.FLG_DESC, Constants.CENFLG);
|
|
340
|
+
// compression method
|
|
341
|
+
data.writeUInt16LE(_method, Constants.CENHOW);
|
|
342
|
+
// modification time (2 bytes time, 2 bytes date)
|
|
343
|
+
data.writeUInt32LE(_time, Constants.CENTIM);
|
|
344
|
+
// uncompressed file crc-32 value
|
|
345
|
+
data.writeUInt32LE(_crc, Constants.CENCRC);
|
|
346
|
+
// compressed size
|
|
347
|
+
data.writeUInt32LE(_compressedSize, Constants.CENSIZ);
|
|
348
|
+
// uncompressed size
|
|
349
|
+
data.writeUInt32LE(_size, Constants.CENLEN);
|
|
350
|
+
// filename length
|
|
351
|
+
data.writeUInt16LE(_fnameLen, Constants.CENNAM);
|
|
352
|
+
// extra field length
|
|
353
|
+
data.writeUInt16LE(_extraLen, Constants.CENEXT);
|
|
354
|
+
// file comment length
|
|
355
|
+
data.writeUInt16LE(_comLen, Constants.CENCOM);
|
|
356
|
+
// volume number start
|
|
357
|
+
data.writeUInt16LE(_diskStart, Constants.CENDSK);
|
|
358
|
+
// internal file attributes
|
|
359
|
+
data.writeUInt16LE(_inattr, Constants.CENATT);
|
|
360
|
+
// external file attributes
|
|
361
|
+
data.writeUInt32LE(_attr, Constants.CENATX);
|
|
362
|
+
// LOC header offset
|
|
363
|
+
data.writeUInt32LE(_offset, Constants.CENOFF);
|
|
364
|
+
return data;
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
toJSON: function () {
|
|
368
|
+
const bytes = function (nr) {
|
|
369
|
+
return nr + " bytes";
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
return {
|
|
373
|
+
made: _verMade,
|
|
374
|
+
version: _version,
|
|
375
|
+
flags: _flags,
|
|
376
|
+
method: Utils.methodToString(_method),
|
|
377
|
+
time: this.time,
|
|
378
|
+
crc: "0x" + _crc.toString(16).toUpperCase(),
|
|
379
|
+
compressedSize: bytes(_compressedSize),
|
|
380
|
+
size: bytes(_size),
|
|
381
|
+
fileNameLength: bytes(_fnameLen),
|
|
382
|
+
extraLength: bytes(_extraLen),
|
|
383
|
+
commentLength: bytes(_comLen),
|
|
384
|
+
diskNumStart: _diskStart,
|
|
385
|
+
inAttr: _inattr,
|
|
386
|
+
attr: _attr,
|
|
387
|
+
offset: _offset,
|
|
388
|
+
centralHeaderSize: bytes(Constants.CENHDR + _fnameLen + _extraLen + _comLen)
|
|
389
|
+
};
|
|
390
|
+
},
|
|
391
|
+
|
|
392
|
+
toString: function () {
|
|
393
|
+
return JSON.stringify(this.toJSON(), null, "\t");
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
var Utils = require("../util"),
|
|
2
|
+
Constants = Utils.Constants;
|
|
3
|
+
|
|
4
|
+
/* The entries in the end of central directory */
|
|
5
|
+
module.exports = function () {
|
|
6
|
+
var _volumeEntries = 0,
|
|
7
|
+
_totalEntries = 0,
|
|
8
|
+
_size = 0,
|
|
9
|
+
_offset = 0,
|
|
10
|
+
_commentLength = 0;
|
|
11
|
+
|
|
12
|
+
const needsZip64 = () => _volumeEntries > Constants.EF_ZIP64_OR_16 || _totalEntries > Constants.EF_ZIP64_OR_16 || _size > Constants.EF_ZIP64_OR_32 || _offset > Constants.EF_ZIP64_OR_32;
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
get diskEntries() {
|
|
16
|
+
return _volumeEntries;
|
|
17
|
+
},
|
|
18
|
+
set diskEntries(/*Number*/ val) {
|
|
19
|
+
_volumeEntries = _totalEntries = val;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
get totalEntries() {
|
|
23
|
+
return _totalEntries;
|
|
24
|
+
},
|
|
25
|
+
set totalEntries(/*Number*/ val) {
|
|
26
|
+
_totalEntries = _volumeEntries = val;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
get size() {
|
|
30
|
+
return _size;
|
|
31
|
+
},
|
|
32
|
+
set size(/*Number*/ val) {
|
|
33
|
+
_size = val;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
get offset() {
|
|
37
|
+
return _offset;
|
|
38
|
+
},
|
|
39
|
+
set offset(/*Number*/ val) {
|
|
40
|
+
_offset = val;
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
get commentLength() {
|
|
44
|
+
return _commentLength;
|
|
45
|
+
},
|
|
46
|
+
set commentLength(/*Number*/ val) {
|
|
47
|
+
_commentLength = val;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
get mainHeaderSize() {
|
|
51
|
+
return (needsZip64() ? Constants.ZIP64HDR + Constants.END64HDR : 0) + Constants.ENDHDR + _commentLength;
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
loadFromBinary: function (/*Buffer*/ data) {
|
|
55
|
+
// data should be 22 bytes and start with "PK 05 06"
|
|
56
|
+
// or be 56+ bytes and start with "PK 06 06" for Zip64
|
|
57
|
+
if (
|
|
58
|
+
(data.length !== Constants.ENDHDR || data.readUInt32LE(0) !== Constants.ENDSIG) &&
|
|
59
|
+
(data.length < Constants.ZIP64HDR || data.readUInt32LE(0) !== Constants.ZIP64SIG)
|
|
60
|
+
) {
|
|
61
|
+
throw Utils.Errors.INVALID_END();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (data.readUInt32LE(0) === Constants.ENDSIG) {
|
|
65
|
+
// number of entries on this volume
|
|
66
|
+
_volumeEntries = data.readUInt16LE(Constants.ENDSUB);
|
|
67
|
+
// total number of entries
|
|
68
|
+
_totalEntries = data.readUInt16LE(Constants.ENDTOT);
|
|
69
|
+
// central directory size in bytes
|
|
70
|
+
_size = data.readUInt32LE(Constants.ENDSIZ);
|
|
71
|
+
// offset of first CEN header
|
|
72
|
+
_offset = data.readUInt32LE(Constants.ENDOFF);
|
|
73
|
+
// zip file comment length
|
|
74
|
+
_commentLength = data.readUInt16LE(Constants.ENDCOM);
|
|
75
|
+
} else {
|
|
76
|
+
// number of entries on this volume
|
|
77
|
+
_volumeEntries = Utils.readBigUInt64LE(data, Constants.ZIP64SUB);
|
|
78
|
+
// total number of entries
|
|
79
|
+
_totalEntries = Utils.readBigUInt64LE(data, Constants.ZIP64TOT);
|
|
80
|
+
// central directory size in bytes
|
|
81
|
+
_size = Utils.readBigUInt64LE(data, Constants.ZIP64SIZB);
|
|
82
|
+
// offset of first CEN header
|
|
83
|
+
_offset = Utils.readBigUInt64LE(data, Constants.ZIP64OFF);
|
|
84
|
+
|
|
85
|
+
_commentLength = 0;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
toBinary: function () {
|
|
90
|
+
if (!needsZip64()) {
|
|
91
|
+
var b = Buffer.alloc(Constants.ENDHDR + _commentLength);
|
|
92
|
+
// "PK 05 06" signature
|
|
93
|
+
b.writeUInt32LE(Constants.ENDSIG, 0);
|
|
94
|
+
b.writeUInt32LE(0, 4);
|
|
95
|
+
// number of entries on this volume
|
|
96
|
+
b.writeUInt16LE(_volumeEntries, Constants.ENDSUB);
|
|
97
|
+
// total number of entries
|
|
98
|
+
b.writeUInt16LE(_totalEntries, Constants.ENDTOT);
|
|
99
|
+
// central directory size in bytes
|
|
100
|
+
b.writeUInt32LE(_size, Constants.ENDSIZ);
|
|
101
|
+
// offset of first CEN header
|
|
102
|
+
b.writeUInt32LE(_offset, Constants.ENDOFF);
|
|
103
|
+
// zip file comment length
|
|
104
|
+
b.writeUInt16LE(_commentLength, Constants.ENDCOM);
|
|
105
|
+
// fill comment memory with spaces so no garbage is left there
|
|
106
|
+
b.fill(" ", Constants.ENDHDR);
|
|
107
|
+
|
|
108
|
+
return b;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var b = Buffer.alloc(this.mainHeaderSize);
|
|
112
|
+
let offset = 0;
|
|
113
|
+
|
|
114
|
+
// Zip64 end of central directory record.
|
|
115
|
+
b.writeUInt32LE(Constants.ZIP64SIG, offset);
|
|
116
|
+
Utils.writeBigUInt64LE(b, Constants.ZIP64HDR - Constants.ZIP64LEAD, offset + Constants.ZIP64SIZE);
|
|
117
|
+
b.writeUInt16LE(45, offset + Constants.ZIP64VEM);
|
|
118
|
+
b.writeUInt16LE(45, offset + Constants.ZIP64VER);
|
|
119
|
+
b.writeUInt32LE(0, offset + Constants.ZIP64DSK);
|
|
120
|
+
b.writeUInt32LE(0, offset + Constants.ZIP64DSKDIR);
|
|
121
|
+
Utils.writeBigUInt64LE(b, _volumeEntries, offset + Constants.ZIP64SUB);
|
|
122
|
+
Utils.writeBigUInt64LE(b, _totalEntries, offset + Constants.ZIP64TOT);
|
|
123
|
+
Utils.writeBigUInt64LE(b, _size, offset + Constants.ZIP64SIZB);
|
|
124
|
+
Utils.writeBigUInt64LE(b, _offset, offset + Constants.ZIP64OFF);
|
|
125
|
+
|
|
126
|
+
const zip64EndOffset = _offset + _size;
|
|
127
|
+
offset += Constants.ZIP64HDR;
|
|
128
|
+
|
|
129
|
+
// Zip64 end of central directory locator.
|
|
130
|
+
b.writeUInt32LE(Constants.END64SIG, offset);
|
|
131
|
+
b.writeUInt32LE(0, offset + Constants.END64START);
|
|
132
|
+
Utils.writeBigUInt64LE(b, zip64EndOffset, offset + Constants.END64OFF);
|
|
133
|
+
b.writeUInt32LE(1, offset + Constants.END64NUMDISKS);
|
|
134
|
+
offset += Constants.END64HDR;
|
|
135
|
+
|
|
136
|
+
// "PK 05 06" signature
|
|
137
|
+
b.writeUInt32LE(Constants.ENDSIG, offset);
|
|
138
|
+
b.writeUInt32LE(0, offset + 4);
|
|
139
|
+
// number of entries on this volume
|
|
140
|
+
b.writeUInt16LE(Math.min(_volumeEntries, Constants.EF_ZIP64_OR_16), offset + Constants.ENDSUB);
|
|
141
|
+
// total number of entries
|
|
142
|
+
b.writeUInt16LE(Math.min(_totalEntries, Constants.EF_ZIP64_OR_16), offset + Constants.ENDTOT);
|
|
143
|
+
// central directory size in bytes
|
|
144
|
+
b.writeUInt32LE(Math.min(_size, Constants.EF_ZIP64_OR_32), offset + Constants.ENDSIZ);
|
|
145
|
+
// offset of first CEN header
|
|
146
|
+
b.writeUInt32LE(Math.min(_offset, Constants.EF_ZIP64_OR_32), offset + Constants.ENDOFF);
|
|
147
|
+
// zip file comment length
|
|
148
|
+
b.writeUInt16LE(_commentLength, offset + Constants.ENDCOM);
|
|
149
|
+
// fill comment memory with spaces so no garbage is left there
|
|
150
|
+
b.fill(" ", offset + Constants.ENDHDR);
|
|
151
|
+
|
|
152
|
+
return b;
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
toJSON: function () {
|
|
156
|
+
// creates 0x0000 style output
|
|
157
|
+
const offset = function (nr, len) {
|
|
158
|
+
let offs = nr.toString(16).toUpperCase();
|
|
159
|
+
while (offs.length < len) offs = "0" + offs;
|
|
160
|
+
return "0x" + offs;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
diskEntries: _volumeEntries,
|
|
165
|
+
totalEntries: _totalEntries,
|
|
166
|
+
size: _size + " bytes",
|
|
167
|
+
offset: offset(_offset, 4),
|
|
168
|
+
commentLength: _commentLength
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
toString: function () {
|
|
173
|
+
return JSON.stringify(this.toJSON(), null, "\t");
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
// Misspelled
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module.exports = function (/*Buffer*/ inbuf) {
|
|
2
|
+
var zlib = require("zlib");
|
|
3
|
+
|
|
4
|
+
var opts = { chunkSize: (parseInt(inbuf.length / 1024) + 1) * 1024 };
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
deflate: function () {
|
|
8
|
+
return zlib.deflateRawSync(inbuf, opts);
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
deflateAsync: function (/*Function*/ callback) {
|
|
12
|
+
var tmp = zlib.createDeflateRaw(opts),
|
|
13
|
+
parts = [],
|
|
14
|
+
total = 0;
|
|
15
|
+
tmp.on("data", function (data) {
|
|
16
|
+
parts.push(data);
|
|
17
|
+
total += data.length;
|
|
18
|
+
});
|
|
19
|
+
tmp.on("end", function () {
|
|
20
|
+
var buf = Buffer.alloc(total),
|
|
21
|
+
written = 0;
|
|
22
|
+
buf.fill(0);
|
|
23
|
+
for (var i = 0; i < parts.length; i++) {
|
|
24
|
+
var part = parts[i];
|
|
25
|
+
part.copy(buf, written);
|
|
26
|
+
written += part.length;
|
|
27
|
+
}
|
|
28
|
+
callback && callback(buf);
|
|
29
|
+
});
|
|
30
|
+
tmp.end(inbuf);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const version = +(process?.versions?.node ?? "").split(".")[0] || 0;
|
|
2
|
+
const Errors = require("../util/errors");
|
|
3
|
+
|
|
4
|
+
module.exports = function (/*Buffer*/ inbuf, /*number*/ expectedLength) {
|
|
5
|
+
var zlib = require("zlib");
|
|
6
|
+
// Cap decompression output at the entry's declared uncompressed size to bound
|
|
7
|
+
// decompression bombs (CVE-2026-39244). A declared size of 0 must not disable
|
|
8
|
+
// the cap: a genuinely empty entry inflates to 0 bytes, so a 1-byte floor
|
|
9
|
+
// still lets it through while stopping a bomb that lies about its size
|
|
10
|
+
// (GHSA-rcw4-f5rp-g42v). zlib requires maxOutputLength >= 1.
|
|
11
|
+
const maxOutputLength = expectedLength > 0 ? expectedLength : 1;
|
|
12
|
+
const option = version >= 15 ? { maxOutputLength } : {};
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
inflate: function () {
|
|
16
|
+
return zlib.inflateRawSync(inbuf, option);
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
inflateAsync: function (/*Function*/ callback) {
|
|
20
|
+
var tmp = zlib.createInflateRaw(option),
|
|
21
|
+
parts = [],
|
|
22
|
+
total = 0,
|
|
23
|
+
done = false;
|
|
24
|
+
const fail = function (err) {
|
|
25
|
+
if (done) return;
|
|
26
|
+
done = true;
|
|
27
|
+
tmp.destroy();
|
|
28
|
+
callback && callback(Buffer.alloc(0), err);
|
|
29
|
+
};
|
|
30
|
+
// Route stream errors (e.g. Z_DATA_ERROR on malformed input) through the
|
|
31
|
+
// callback. Without an "error" listener zlib re-throws the event as an
|
|
32
|
+
// uncaught exception on a later tick, crashing the host process instead
|
|
33
|
+
// of failing the call (GHSA-8238-w5pm-2374).
|
|
34
|
+
tmp.on("error", function (err) {
|
|
35
|
+
fail(err);
|
|
36
|
+
});
|
|
37
|
+
tmp.on("data", function (data) {
|
|
38
|
+
if (done) return;
|
|
39
|
+
total += data.length;
|
|
40
|
+
// The streaming API ignores maxOutputLength, so enforce the cap by
|
|
41
|
+
// hand; otherwise the async path decompresses without limit while the
|
|
42
|
+
// sync path is capped (GHSA-v429-h5qx-84wm, GHSA-c6fg-446q-cg94).
|
|
43
|
+
if (total > maxOutputLength) {
|
|
44
|
+
return fail(Errors.MAX_OUTPUT_EXCEEDED());
|
|
45
|
+
}
|
|
46
|
+
parts.push(data);
|
|
47
|
+
});
|
|
48
|
+
tmp.on("end", function () {
|
|
49
|
+
if (done) return;
|
|
50
|
+
done = true;
|
|
51
|
+
var buf = Buffer.alloc(total),
|
|
52
|
+
written = 0;
|
|
53
|
+
buf.fill(0);
|
|
54
|
+
for (var i = 0; i < parts.length; i++) {
|
|
55
|
+
var part = parts[i];
|
|
56
|
+
part.copy(buf, written);
|
|
57
|
+
written += part.length;
|
|
58
|
+
}
|
|
59
|
+
callback && callback(buf);
|
|
60
|
+
});
|
|
61
|
+
tmp.end(inbuf);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
};
|