formacao
This commit is contained in:
+59
-37
@@ -78,23 +78,45 @@ class Header {
|
||||
if (!buf || !(buf.length >= off + 512)) {
|
||||
throw new Error('need 512 bytes for header');
|
||||
}
|
||||
this.path = ex?.path ?? decString(buf, off, 100);
|
||||
this.mode = ex?.mode ?? gex?.mode ?? decNumber(buf, off + 100, 8);
|
||||
this.uid = ex?.uid ?? gex?.uid ?? decNumber(buf, off + 108, 8);
|
||||
this.gid = ex?.gid ?? gex?.gid ?? decNumber(buf, off + 116, 8);
|
||||
this.size = ex?.size ?? gex?.size ?? decNumber(buf, off + 124, 12);
|
||||
// Decode the typeflag (independent of any pending PAX/GNU extended header)
|
||||
// up front so we can tell whether THIS block is itself an intermediary
|
||||
// extension header (PAX `x`/`g`, GNU long-name `L`, GNU long-link `K`).
|
||||
// Per POSIX pax, a PAX extended header describes the *next file entry*, not
|
||||
// the extension headers that may sit between it and that file. Applying the
|
||||
// pending PAX overrides (notably `size`) to an intervening `L`/`K`/`x`/`g`
|
||||
// header desynchronizes the stream relative to other tar implementations
|
||||
// and enables tar interpretation-conflict / file-smuggling attacks.
|
||||
const t = decString(buf, off + 156, 1);
|
||||
const isNormalFS = types.normalFsTypes.has(t);
|
||||
const exForFields = isNormalFS ? ex : undefined;
|
||||
const gexForFields = isNormalFS ? gex : undefined;
|
||||
this.path = exForFields?.path ?? decString(buf, off, 100);
|
||||
this.mode =
|
||||
exForFields?.mode ??
|
||||
gexForFields?.mode ??
|
||||
decNumber(buf, off + 100, 8);
|
||||
this.uid =
|
||||
exForFields?.uid ?? gexForFields?.uid ?? decNumber(buf, off + 108, 8);
|
||||
this.gid =
|
||||
exForFields?.gid ?? gexForFields?.gid ?? decNumber(buf, off + 116, 8);
|
||||
this.size =
|
||||
exForFields?.size ??
|
||||
gexForFields?.size ??
|
||||
decNumber(buf, off + 124, 12);
|
||||
this.mtime =
|
||||
ex?.mtime ?? gex?.mtime ?? decDate(buf, off + 136, 12);
|
||||
exForFields?.mtime ??
|
||||
gexForFields?.mtime ??
|
||||
decDate(buf, off + 136, 12);
|
||||
this.cksum = decNumber(buf, off + 148, 12);
|
||||
// if we have extended or global extended headers, apply them now
|
||||
// See https://github.com/npm/node-tar/pull/187
|
||||
// Apply global before local, so it overrides
|
||||
if (gex)
|
||||
this.#slurp(gex, true);
|
||||
if (ex)
|
||||
this.#slurp(ex);
|
||||
// Apply global before local, so it overrides. Never slurp the pending
|
||||
// extended-header fields onto an intermediary extension header.
|
||||
if (gexForFields)
|
||||
this.#slurp(gexForFields, true);
|
||||
if (exForFields)
|
||||
this.#slurp(exForFields);
|
||||
// old tar versions marked dirs as a file with a trailing /
|
||||
const t = decString(buf, off + 156, 1);
|
||||
if (types.isCode(t)) {
|
||||
this.#type = t || '0';
|
||||
}
|
||||
@@ -110,17 +132,26 @@ class Header {
|
||||
this.size = 0;
|
||||
}
|
||||
this.linkpath = decString(buf, off + 157, 100);
|
||||
if (buf.subarray(off + 257, off + 265).toString() ===
|
||||
'ustar\u000000') {
|
||||
if (buf.subarray(off + 257, off + 265).toString() === 'ustar\u000000') {
|
||||
/* c8 ignore start */
|
||||
this.uname =
|
||||
ex?.uname ?? gex?.uname ?? decString(buf, off + 265, 32);
|
||||
exForFields?.uname ??
|
||||
gexForFields?.uname ??
|
||||
decString(buf, off + 265, 32);
|
||||
this.gname =
|
||||
ex?.gname ?? gex?.gname ?? decString(buf, off + 297, 32);
|
||||
exForFields?.gname ??
|
||||
gexForFields?.gname ??
|
||||
decString(buf, off + 297, 32);
|
||||
this.devmaj =
|
||||
ex?.devmaj ?? gex?.devmaj ?? decNumber(buf, off + 329, 8) ?? 0;
|
||||
exForFields?.devmaj ??
|
||||
gexForFields?.devmaj ??
|
||||
decNumber(buf, off + 329, 8) ??
|
||||
0;
|
||||
this.devmin =
|
||||
ex?.devmin ?? gex?.devmin ?? decNumber(buf, off + 337, 8) ?? 0;
|
||||
exForFields?.devmin ??
|
||||
gexForFields?.devmin ??
|
||||
decNumber(buf, off + 337, 8) ??
|
||||
0;
|
||||
/* c8 ignore stop */
|
||||
if (buf[off + 475] !== 0) {
|
||||
// definitely a prefix, definitely >130 chars.
|
||||
@@ -133,10 +164,8 @@ class Header {
|
||||
this.path = prefix + '/' + this.path;
|
||||
}
|
||||
/* c8 ignore start */
|
||||
this.atime =
|
||||
ex?.atime ?? gex?.atime ?? decDate(buf, off + 476, 12);
|
||||
this.ctime =
|
||||
ex?.ctime ?? gex?.ctime ?? decDate(buf, off + 488, 12);
|
||||
this.atime = ex?.atime ?? gex?.atime ?? decDate(buf, off + 476, 12);
|
||||
this.ctime = ex?.ctime ?? gex?.ctime ?? decDate(buf, off + 488, 12);
|
||||
/* c8 ignore stop */
|
||||
}
|
||||
}
|
||||
@@ -180,17 +209,12 @@ class Header {
|
||||
const prefix = split[1];
|
||||
this.needPax = !!split[2];
|
||||
this.needPax = encString(buf, off, 100, path) || this.needPax;
|
||||
this.needPax =
|
||||
encNumber(buf, off + 100, 8, this.mode) || this.needPax;
|
||||
this.needPax =
|
||||
encNumber(buf, off + 108, 8, this.uid) || this.needPax;
|
||||
this.needPax =
|
||||
encNumber(buf, off + 116, 8, this.gid) || this.needPax;
|
||||
this.needPax =
|
||||
encNumber(buf, off + 124, 12, this.size) || this.needPax;
|
||||
this.needPax =
|
||||
encDate(buf, off + 136, 12, this.mtime) || this.needPax;
|
||||
buf[off + 156] = this.#type.charCodeAt(0);
|
||||
this.needPax = encNumber(buf, off + 100, 8, this.mode) || this.needPax;
|
||||
this.needPax = encNumber(buf, off + 108, 8, this.uid) || this.needPax;
|
||||
this.needPax = encNumber(buf, off + 116, 8, this.gid) || this.needPax;
|
||||
this.needPax = encNumber(buf, off + 124, 12, this.size) || this.needPax;
|
||||
this.needPax = encDate(buf, off + 136, 12, this.mtime) || this.needPax;
|
||||
buf[off + 156] = Number(this.#type.codePointAt(0));
|
||||
this.needPax =
|
||||
encString(buf, off + 157, 100, this.linkpath) || this.needPax;
|
||||
buf.write('ustar\u000000', off + 257, 8);
|
||||
@@ -205,12 +229,10 @@ class Header {
|
||||
this.needPax =
|
||||
encString(buf, off + 345, prefixSize, prefix) || this.needPax;
|
||||
if (buf[off + 475] !== 0) {
|
||||
this.needPax =
|
||||
encString(buf, off + 345, 155, prefix) || this.needPax;
|
||||
this.needPax = encString(buf, off + 345, 155, prefix) || this.needPax;
|
||||
}
|
||||
else {
|
||||
this.needPax =
|
||||
encString(buf, off + 345, 130, prefix) || this.needPax;
|
||||
this.needPax = encString(buf, off + 345, 130, prefix) || this.needPax;
|
||||
this.needPax =
|
||||
encDate(buf, off + 476, 12, this.atime) || this.needPax;
|
||||
this.needPax =
|
||||
|
||||
Reference in New Issue
Block a user