tar 6.1.15 → 6.2.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 +10 -0
- package/lib/pack.js +18 -6
- package/lib/parse.js +46 -3
- package/lib/replace.js +1 -1
- package/lib/unpack.js +22 -5
- package/lib/update.js +1 -1
- package/package.json +2 -7
package/README.md
CHANGED
|
@@ -115,6 +115,8 @@ Handlers receive 3 arguments:
|
|
|
115
115
|
encountered an error which prevented it from being unpacked. This occurs
|
|
116
116
|
when:
|
|
117
117
|
- an unrecoverable fs error happens during unpacking,
|
|
118
|
+
- an entry is trying to extract into an excessively deep
|
|
119
|
+
location (by default, limited to 1024 subfolders),
|
|
118
120
|
- an entry has `..` in the path and `preservePaths` is not set, or
|
|
119
121
|
- an entry is extracting through a symbolic link, when `preservePaths` is
|
|
120
122
|
not set.
|
|
@@ -427,6 +429,10 @@ The following options are supported:
|
|
|
427
429
|
`process.umask()` to determine the default umask value, since tar will
|
|
428
430
|
extract with whatever mode is provided, and let the process `umask` apply
|
|
429
431
|
normally.
|
|
432
|
+
- `maxDepth` The maximum depth of subfolders to extract into. This
|
|
433
|
+
defaults to 1024. Anything deeper than the limit will raise a
|
|
434
|
+
warning and skip the entry. Set to `Infinity` to remove the
|
|
435
|
+
limitation.
|
|
430
436
|
|
|
431
437
|
The following options are mostly internal, but can be modified in some
|
|
432
438
|
advanced use cases, such as re-using caches between runs.
|
|
@@ -749,6 +755,10 @@ Most unpack errors will cause a `warn` event to be emitted. If the
|
|
|
749
755
|
`process.umask()` to determine the default umask value, since tar will
|
|
750
756
|
extract with whatever mode is provided, and let the process `umask` apply
|
|
751
757
|
normally.
|
|
758
|
+
- `maxDepth` The maximum depth of subfolders to extract into. This
|
|
759
|
+
defaults to 1024. Anything deeper than the limit will raise a
|
|
760
|
+
warning and skip the entry. Set to `Infinity` to remove the
|
|
761
|
+
limitation.
|
|
752
762
|
|
|
753
763
|
### class tar.Unpack.Sync
|
|
754
764
|
|
package/lib/pack.js
CHANGED
|
@@ -79,14 +79,26 @@ const Pack = warner(class Pack extends Minipass {
|
|
|
79
79
|
|
|
80
80
|
this.portable = !!opt.portable
|
|
81
81
|
this.zip = null
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
|
|
83
|
+
if (opt.gzip || opt.brotli) {
|
|
84
|
+
if (opt.gzip && opt.brotli) {
|
|
85
|
+
throw new TypeError('gzip and brotli are mutually exclusive')
|
|
85
86
|
}
|
|
86
|
-
if (
|
|
87
|
-
opt.gzip
|
|
87
|
+
if (opt.gzip) {
|
|
88
|
+
if (typeof opt.gzip !== 'object') {
|
|
89
|
+
opt.gzip = {}
|
|
90
|
+
}
|
|
91
|
+
if (this.portable) {
|
|
92
|
+
opt.gzip.portable = true
|
|
93
|
+
}
|
|
94
|
+
this.zip = new zlib.Gzip(opt.gzip)
|
|
95
|
+
}
|
|
96
|
+
if (opt.brotli) {
|
|
97
|
+
if (typeof opt.brotli !== 'object') {
|
|
98
|
+
opt.brotli = {}
|
|
99
|
+
}
|
|
100
|
+
this.zip = new zlib.BrotliCompress(opt.brotli)
|
|
88
101
|
}
|
|
89
|
-
this.zip = new zlib.Gzip(opt.gzip)
|
|
90
102
|
this.zip.on('data', chunk => super.write(chunk))
|
|
91
103
|
this.zip.on('end', _ => super.end())
|
|
92
104
|
this.zip.on('drain', _ => this[ONDRAIN]())
|
package/lib/parse.js
CHANGED
|
@@ -97,6 +97,16 @@ module.exports = warner(class Parser extends EE {
|
|
|
97
97
|
this.strict = !!opt.strict
|
|
98
98
|
this.maxMetaEntrySize = opt.maxMetaEntrySize || maxMetaEntrySize
|
|
99
99
|
this.filter = typeof opt.filter === 'function' ? opt.filter : noop
|
|
100
|
+
// Unlike gzip, brotli doesn't have any magic bytes to identify it
|
|
101
|
+
// Users need to explicitly tell us they're extracting a brotli file
|
|
102
|
+
// Or we infer from the file extension
|
|
103
|
+
const isTBR = (opt.file && (
|
|
104
|
+
opt.file.endsWith('.tar.br') || opt.file.endsWith('.tbr')))
|
|
105
|
+
// if it's a tbr file it MIGHT be brotli, but we don't know until
|
|
106
|
+
// we look at it and verify it's not a valid tar file.
|
|
107
|
+
this.brotli = !opt.gzip && opt.brotli !== undefined ? opt.brotli
|
|
108
|
+
: isTBR ? undefined
|
|
109
|
+
: false
|
|
100
110
|
|
|
101
111
|
// have to set this so that streams are ok piping into it
|
|
102
112
|
this.writable = true
|
|
@@ -347,7 +357,9 @@ module.exports = warner(class Parser extends EE {
|
|
|
347
357
|
}
|
|
348
358
|
|
|
349
359
|
// first write, might be gzipped
|
|
350
|
-
|
|
360
|
+
const needSniff = this[UNZIP] === null ||
|
|
361
|
+
this.brotli === undefined && this[UNZIP] === false
|
|
362
|
+
if (needSniff && chunk) {
|
|
351
363
|
if (this[BUFFER]) {
|
|
352
364
|
chunk = Buffer.concat([this[BUFFER], chunk])
|
|
353
365
|
this[BUFFER] = null
|
|
@@ -356,15 +368,45 @@ module.exports = warner(class Parser extends EE {
|
|
|
356
368
|
this[BUFFER] = chunk
|
|
357
369
|
return true
|
|
358
370
|
}
|
|
371
|
+
|
|
372
|
+
// look for gzip header
|
|
359
373
|
for (let i = 0; this[UNZIP] === null && i < gzipHeader.length; i++) {
|
|
360
374
|
if (chunk[i] !== gzipHeader[i]) {
|
|
361
375
|
this[UNZIP] = false
|
|
362
376
|
}
|
|
363
377
|
}
|
|
364
|
-
|
|
378
|
+
|
|
379
|
+
const maybeBrotli = this.brotli === undefined
|
|
380
|
+
if (this[UNZIP] === false && maybeBrotli) {
|
|
381
|
+
// read the first header to see if it's a valid tar file. If so,
|
|
382
|
+
// we can safely assume that it's not actually brotli, despite the
|
|
383
|
+
// .tbr or .tar.br file extension.
|
|
384
|
+
// if we ended before getting a full chunk, yes, def brotli
|
|
385
|
+
if (chunk.length < 512) {
|
|
386
|
+
if (this[ENDED]) {
|
|
387
|
+
this.brotli = true
|
|
388
|
+
} else {
|
|
389
|
+
this[BUFFER] = chunk
|
|
390
|
+
return true
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
// if it's tar, it's pretty reliably not brotli, chances of
|
|
394
|
+
// that happening are astronomical.
|
|
395
|
+
try {
|
|
396
|
+
new Header(chunk.slice(0, 512))
|
|
397
|
+
this.brotli = false
|
|
398
|
+
} catch (_) {
|
|
399
|
+
this.brotli = true
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (this[UNZIP] === null || (this[UNZIP] === false && this.brotli)) {
|
|
365
405
|
const ended = this[ENDED]
|
|
366
406
|
this[ENDED] = false
|
|
367
|
-
this[UNZIP] =
|
|
407
|
+
this[UNZIP] = this[UNZIP] === null
|
|
408
|
+
? new zlib.Unzip()
|
|
409
|
+
: new zlib.BrotliDecompress()
|
|
368
410
|
this[UNZIP].on('data', chunk => this[CONSUMECHUNK](chunk))
|
|
369
411
|
this[UNZIP].on('error', er => this.abort(er))
|
|
370
412
|
this[UNZIP].on('end', _ => {
|
|
@@ -502,6 +544,7 @@ module.exports = warner(class Parser extends EE {
|
|
|
502
544
|
this[UNZIP].end(chunk)
|
|
503
545
|
} else {
|
|
504
546
|
this[ENDED] = true
|
|
547
|
+
if (this.brotli === undefined) chunk = chunk || Buffer.alloc(0)
|
|
505
548
|
this.write(chunk)
|
|
506
549
|
}
|
|
507
550
|
}
|
package/lib/replace.js
CHANGED
|
@@ -23,7 +23,7 @@ module.exports = (opt_, files, cb) => {
|
|
|
23
23
|
throw new TypeError('file is required')
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
if (opt.gzip) {
|
|
26
|
+
if (opt.gzip || opt.brotli || opt.file.endsWith('.br') || opt.file.endsWith('.tbr')) {
|
|
27
27
|
throw new TypeError('cannot append to compressed archives')
|
|
28
28
|
}
|
|
29
29
|
|
package/lib/unpack.js
CHANGED
|
@@ -48,6 +48,7 @@ const crypto = require('crypto')
|
|
|
48
48
|
const getFlag = require('./get-write-flag.js')
|
|
49
49
|
const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform
|
|
50
50
|
const isWindows = platform === 'win32'
|
|
51
|
+
const DEFAULT_MAX_DEPTH = 1024
|
|
51
52
|
|
|
52
53
|
// Unlinks on Windows are not atomic.
|
|
53
54
|
//
|
|
@@ -181,6 +182,12 @@ class Unpack extends Parser {
|
|
|
181
182
|
this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ?
|
|
182
183
|
process.getgid() : null
|
|
183
184
|
|
|
185
|
+
// prevent excessively deep nesting of subfolders
|
|
186
|
+
// set to `Infinity` to remove this restriction
|
|
187
|
+
this.maxDepth = typeof opt.maxDepth === 'number'
|
|
188
|
+
? opt.maxDepth
|
|
189
|
+
: DEFAULT_MAX_DEPTH
|
|
190
|
+
|
|
184
191
|
// mostly just for testing, but useful in some cases.
|
|
185
192
|
// Forcibly trigger a chown on every entry, no matter what
|
|
186
193
|
this.forceChown = opt.forceChown === true
|
|
@@ -238,13 +245,13 @@ class Unpack extends Parser {
|
|
|
238
245
|
}
|
|
239
246
|
|
|
240
247
|
[CHECKPATH] (entry) {
|
|
248
|
+
const p = normPath(entry.path)
|
|
249
|
+
const parts = p.split('/')
|
|
250
|
+
|
|
241
251
|
if (this.strip) {
|
|
242
|
-
const parts = normPath(entry.path).split('/')
|
|
243
252
|
if (parts.length < this.strip) {
|
|
244
253
|
return false
|
|
245
254
|
}
|
|
246
|
-
entry.path = parts.slice(this.strip).join('/')
|
|
247
|
-
|
|
248
255
|
if (entry.type === 'Link') {
|
|
249
256
|
const linkparts = normPath(entry.linkpath).split('/')
|
|
250
257
|
if (linkparts.length >= this.strip) {
|
|
@@ -253,11 +260,21 @@ class Unpack extends Parser {
|
|
|
253
260
|
return false
|
|
254
261
|
}
|
|
255
262
|
}
|
|
263
|
+
parts.splice(0, this.strip)
|
|
264
|
+
entry.path = parts.join('/')
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (isFinite(this.maxDepth) && parts.length > this.maxDepth) {
|
|
268
|
+
this.warn('TAR_ENTRY_ERROR', 'path excessively deep', {
|
|
269
|
+
entry,
|
|
270
|
+
path: p,
|
|
271
|
+
depth: parts.length,
|
|
272
|
+
maxDepth: this.maxDepth,
|
|
273
|
+
})
|
|
274
|
+
return false
|
|
256
275
|
}
|
|
257
276
|
|
|
258
277
|
if (!this.preservePaths) {
|
|
259
|
-
const p = normPath(entry.path)
|
|
260
|
-
const parts = p.split('/')
|
|
261
278
|
if (parts.includes('..') || isWindows && /^[a-z]:\.\.$/i.test(parts[0])) {
|
|
262
279
|
this.warn('TAR_ENTRY_ERROR', `path contains '..'`, {
|
|
263
280
|
entry,
|
package/lib/update.js
CHANGED
|
@@ -13,7 +13,7 @@ module.exports = (opt_, files, cb) => {
|
|
|
13
13
|
throw new TypeError('file is required')
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
if (opt.gzip) {
|
|
16
|
+
if (opt.gzip || opt.brotli || opt.file.endsWith('.br') || opt.file.endsWith('.tbr')) {
|
|
17
17
|
throw new TypeError('cannot append to compressed archives')
|
|
18
18
|
}
|
|
19
19
|
|
package/package.json
CHANGED
|
@@ -2,20 +2,15 @@
|
|
|
2
2
|
"author": "GitHub Inc.",
|
|
3
3
|
"name": "tar",
|
|
4
4
|
"description": "tar for node",
|
|
5
|
-
"version": "6.1
|
|
5
|
+
"version": "6.2.1",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/isaacs/node-tar.git"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"genparse": "node scripts/generate-parse-fixtures.js",
|
|
12
|
-
"template-oss-apply": "template-oss-apply --force",
|
|
13
|
-
"lint": "eslint \"**/*.js\"",
|
|
14
|
-
"postlint": "template-oss-check",
|
|
15
|
-
"lintfix": "npm run lint -- --fix",
|
|
16
12
|
"snap": "tap",
|
|
17
|
-
"test": "tap"
|
|
18
|
-
"posttest": "npm run lint"
|
|
13
|
+
"test": "tap"
|
|
19
14
|
},
|
|
20
15
|
"dependencies": {
|
|
21
16
|
"chownr": "^2.0.0",
|