tar 6.2.0 → 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/unpack.js +22 -5
- package/package.json +1 -1
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/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,
|