formacao
This commit is contained in:
+38
-63
@@ -167,8 +167,7 @@ class Unpack extends parse_js_1.Parser {
|
||||
this.chmod = !!opt.chmod;
|
||||
if (typeof opt.uid === 'number' || typeof opt.gid === 'number') {
|
||||
// need both or neither
|
||||
if (typeof opt.uid !== 'number' ||
|
||||
typeof opt.gid !== 'number') {
|
||||
if (typeof opt.uid !== 'number' || typeof opt.gid !== 'number') {
|
||||
throw new TypeError('cannot set owner without number uid and gid');
|
||||
}
|
||||
if (opt.preserveOwner) {
|
||||
@@ -184,13 +183,10 @@ class Unpack extends parse_js_1.Parser {
|
||||
this.setOwner = false;
|
||||
}
|
||||
// default true for root
|
||||
if (opt.preserveOwner === undefined &&
|
||||
typeof opt.uid !== 'number') {
|
||||
this.preserveOwner = !!(process.getuid && process.getuid() === 0);
|
||||
}
|
||||
else {
|
||||
this.preserveOwner = !!opt.preserveOwner;
|
||||
}
|
||||
this.preserveOwner =
|
||||
opt.preserveOwner === undefined && typeof opt.uid !== 'number' ?
|
||||
!!(process.getuid && process.getuid() === 0)
|
||||
: !!opt.preserveOwner;
|
||||
this.processUid =
|
||||
(this.preserveOwner || this.setOwner) && process.getuid ?
|
||||
process.getuid()
|
||||
@@ -202,9 +198,7 @@ class Unpack extends parse_js_1.Parser {
|
||||
// prevent excessively deep nesting of subfolders
|
||||
// set to `Infinity` to remove this restriction
|
||||
this.maxDepth =
|
||||
typeof opt.maxDepth === 'number' ?
|
||||
opt.maxDepth
|
||||
: DEFAULT_MAX_DEPTH;
|
||||
typeof opt.maxDepth === 'number' ? opt.maxDepth : DEFAULT_MAX_DEPTH;
|
||||
// mostly just for testing, but useful in some cases.
|
||||
// Forcibly trigger a chown on every entry, no matter what
|
||||
this.forceChown = opt.forceChown === true;
|
||||
@@ -262,7 +256,7 @@ class Unpack extends parse_js_1.Parser {
|
||||
return true;
|
||||
// strip off the root
|
||||
const [root, stripped] = (0, strip_absolute_path_js_1.stripAbsolutePath)(p);
|
||||
const parts = stripped.replace(/\\/g, '/').split('/');
|
||||
const parts = stripped.replaceAll(/\\/g, '/').split('/');
|
||||
if (parts.includes('..') ||
|
||||
/* c8 ignore next */
|
||||
(isWindows && /^[a-z]:\.\.$/i.test(parts[0] ?? ''))) {
|
||||
@@ -278,20 +272,18 @@ class Unpack extends parse_js_1.Parser {
|
||||
// not ok!
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// Resolve linkpath relative to the entry's directory.
|
||||
// `path.posix` is safe to use because we're operating on
|
||||
// tar paths, not a filesystem.
|
||||
const entryDir = node_path_1.default.posix.dirname(entry.path);
|
||||
const resolved = node_path_1.default.posix.normalize(node_path_1.default.posix.join(entryDir, p));
|
||||
// If the resolved path escapes (starts with ..), reject it
|
||||
if (resolved.startsWith('../') || resolved === '..') {
|
||||
this.warn('TAR_ENTRY_ERROR', `${field} escapes extraction directory`, {
|
||||
entry,
|
||||
[field]: p,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
// Resolve linkpath relative to the entry's directory.
|
||||
// `path.posix` is safe to use because we're operating on
|
||||
// tar paths, not a filesystem.
|
||||
const entryDir = node_path_1.default.posix.dirname(entry.path);
|
||||
const resolved = node_path_1.default.posix.normalize(node_path_1.default.posix.join(entryDir, parts.join('/')));
|
||||
// If the resolved path escapes (starts with ..), reject it
|
||||
if (resolved.startsWith('../') || resolved === '..') {
|
||||
this.warn('TAR_ENTRY_ERROR', `${field} escapes extraction directory`, {
|
||||
entry,
|
||||
[field]: p,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (root) {
|
||||
@@ -337,12 +329,10 @@ class Unpack extends parse_js_1.Parser {
|
||||
!this[STRIPABSOLUTEPATH](entry, 'linkpath')) {
|
||||
return false;
|
||||
}
|
||||
if (node_path_1.default.isAbsolute(entry.path)) {
|
||||
entry.absolute = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(entry.path));
|
||||
}
|
||||
else {
|
||||
entry.absolute = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(this.cwd, entry.path));
|
||||
}
|
||||
entry.absolute =
|
||||
node_path_1.default.isAbsolute(entry.path) ?
|
||||
(0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(entry.path))
|
||||
: (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(this.cwd, entry.path));
|
||||
// if we somehow ended up with a path that escapes the cwd, and we are
|
||||
// not in preservePaths mode, then something is fishy! This should have
|
||||
// been prevented above, so ignore this for coverage.
|
||||
@@ -437,8 +427,7 @@ class Unpack extends parse_js_1.Parser {
|
||||
entry.uid !== this.processUid) ||
|
||||
(typeof entry.gid === 'number' &&
|
||||
entry.gid !== this.processGid))) ||
|
||||
(typeof this.uid === 'number' &&
|
||||
this.uid !== this.processUid) ||
|
||||
(typeof this.uid === 'number' && this.uid !== this.processUid) ||
|
||||
(typeof this.gid === 'number' && this.gid !== this.processGid));
|
||||
}
|
||||
[UID](entry) {
|
||||
@@ -448,9 +437,7 @@ class Unpack extends parse_js_1.Parser {
|
||||
return uint32(this.gid, entry.gid, this.processGid);
|
||||
}
|
||||
[FILE](entry, fullyDone) {
|
||||
const mode = typeof entry.mode === 'number' ?
|
||||
entry.mode & 0o7777
|
||||
: this.fmode;
|
||||
const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.fmode;
|
||||
const stream = new fsm.WriteStream(String(entry.absolute), {
|
||||
// slight lie, but it can be numeric flags
|
||||
flags: (0, get_write_flag_js_1.getWriteFlag)(entry.size),
|
||||
@@ -513,16 +500,14 @@ class Unpack extends parse_js_1.Parser {
|
||||
const uid = this[UID](entry);
|
||||
const gid = this[GID](entry);
|
||||
if (typeof uid === 'number' && typeof gid === 'number') {
|
||||
node_fs_1.default.fchown(fd, uid, gid, er => er ?
|
||||
node_fs_1.default.chown(abs, uid, gid, er2 => done(er2 && er))
|
||||
: done());
|
||||
node_fs_1.default.fchown(fd, uid, gid, er => er ? node_fs_1.default.chown(abs, uid, gid, er2 => done(er2 && er)) : done());
|
||||
}
|
||||
}
|
||||
done();
|
||||
});
|
||||
const tx = this.transform ? this.transform(entry) || entry : entry;
|
||||
if (tx !== entry) {
|
||||
tx.on('error', (er) => {
|
||||
tx.on('error', er => {
|
||||
this[ONERROR](er, entry);
|
||||
fullyDone();
|
||||
});
|
||||
@@ -531,9 +516,7 @@ class Unpack extends parse_js_1.Parser {
|
||||
tx.pipe(stream);
|
||||
}
|
||||
[DIRECTORY](entry, fullyDone) {
|
||||
const mode = typeof entry.mode === 'number' ?
|
||||
entry.mode & 0o7777
|
||||
: this.dmode;
|
||||
const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.dmode;
|
||||
this[MKDIR](String(entry.absolute), mode, er => {
|
||||
if (er) {
|
||||
this[ONERROR](er, entry);
|
||||
@@ -669,9 +652,7 @@ class Unpack extends parse_js_1.Parser {
|
||||
}
|
||||
if (st.isDirectory()) {
|
||||
if (entry.type === 'Directory') {
|
||||
const needChmod = this.chmod &&
|
||||
entry.mode &&
|
||||
(st.mode & 0o7777) !== entry.mode;
|
||||
const needChmod = this.chmod && entry.mode && (st.mode & 0o7777) !== entry.mode;
|
||||
const afterChmod = (er) => this[MAKEFS](er ?? null, entry, done);
|
||||
if (!needChmod) {
|
||||
return afterChmod();
|
||||
@@ -782,9 +763,7 @@ class UnpackSync extends Unpack {
|
||||
}
|
||||
if (st.isDirectory()) {
|
||||
if (entry.type === 'Directory') {
|
||||
const needChmod = this.chmod &&
|
||||
entry.mode &&
|
||||
(st.mode & 0o7777) !== entry.mode;
|
||||
const needChmod = this.chmod && entry.mode && (st.mode & 0o7777) !== entry.mode;
|
||||
const [er] = needChmod ?
|
||||
callSync(() => {
|
||||
node_fs_1.default.chmodSync(String(entry.absolute), Number(entry.mode));
|
||||
@@ -804,9 +783,7 @@ class UnpackSync extends Unpack {
|
||||
this[MAKEFS](er, entry);
|
||||
}
|
||||
[FILE](entry, done) {
|
||||
const mode = typeof entry.mode === 'number' ?
|
||||
entry.mode & 0o7777
|
||||
: this.fmode;
|
||||
const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.fmode;
|
||||
const oner = (er) => {
|
||||
let closeError;
|
||||
try {
|
||||
@@ -834,7 +811,7 @@ class UnpackSync extends Unpack {
|
||||
/* c8 ignore stop */
|
||||
const tx = this.transform ? this.transform(entry) || entry : entry;
|
||||
if (tx !== entry) {
|
||||
tx.on('error', (er) => this[ONERROR](er, entry));
|
||||
tx.on('error', er => this[ONERROR](er, entry));
|
||||
entry.pipe(tx);
|
||||
}
|
||||
tx.on('data', (chunk) => {
|
||||
@@ -859,7 +836,7 @@ class UnpackSync extends Unpack {
|
||||
try {
|
||||
node_fs_1.default.utimesSync(String(entry.absolute), atime, mtime);
|
||||
}
|
||||
catch (utimeser) {
|
||||
catch {
|
||||
er = futimeser;
|
||||
}
|
||||
}
|
||||
@@ -874,7 +851,7 @@ class UnpackSync extends Unpack {
|
||||
try {
|
||||
node_fs_1.default.chownSync(String(entry.absolute), Number(uid), Number(gid));
|
||||
}
|
||||
catch (chowner) {
|
||||
catch {
|
||||
er = er || fchowner;
|
||||
}
|
||||
}
|
||||
@@ -883,9 +860,7 @@ class UnpackSync extends Unpack {
|
||||
});
|
||||
}
|
||||
[DIRECTORY](entry, done) {
|
||||
const mode = typeof entry.mode === 'number' ?
|
||||
entry.mode & 0o7777
|
||||
: this.dmode;
|
||||
const mode = typeof entry.mode === 'number' ? entry.mode & 0o7777 : this.dmode;
|
||||
const er = this[MKDIR](String(entry.absolute), mode);
|
||||
if (er) {
|
||||
this[ONERROR](er, entry);
|
||||
@@ -897,13 +872,13 @@ class UnpackSync extends Unpack {
|
||||
node_fs_1.default.utimesSync(String(entry.absolute), entry.atime || new Date(), entry.mtime);
|
||||
/* c8 ignore next */
|
||||
}
|
||||
catch (er) { }
|
||||
catch { }
|
||||
}
|
||||
if (this[DOCHOWN](entry)) {
|
||||
try {
|
||||
node_fs_1.default.chownSync(String(entry.absolute), Number(this[UID](entry)), Number(this[GID](entry)));
|
||||
}
|
||||
catch (er) { }
|
||||
catch { }
|
||||
}
|
||||
done();
|
||||
entry.resume();
|
||||
@@ -927,7 +902,7 @@ class UnpackSync extends Unpack {
|
||||
}
|
||||
}
|
||||
[ENSURE_NO_SYMLINK](_entry, cwd, parts, done, onError) {
|
||||
if (this.preservePaths || !parts.length)
|
||||
if (this.preservePaths || parts.length === 0)
|
||||
return done();
|
||||
let t = cwd;
|
||||
for (const p of parts) {
|
||||
|
||||
Reference in New Issue
Block a user