Skip to content

Commit 5e9f451

Browse files
martinrrmCopilot
andauthored
deps: tar@7.5.22 (#9814)
## Summary Updates the bundled `tar` dependency from `7.5.11` to `7.5.22` on the npm 10 release branch. All production dependency paths now resolve to `tar@7.5.22`. ## Testing - `node . run dependencies --ignore-scripts` - `node . ls tar --all --omit=dev` - `node . audit --omit=dev --json` reports no `tar` vulnerability - `node . test --ignore-scripts` reports only existing Windows environment failures; no tar-related failures Fixes #9801 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3da238b5-ee4e-45ef-a43d-577d015a769b
1 parent 189ba13 commit 5e9f451

39 files changed

Lines changed: 652 additions & 466 deletions

node_modules/tar/dist/commonjs/create.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const createFile = (opt, files) => {
2828
stream.on('close', res);
2929
p.on('error', rej);
3030
});
31-
addFilesAsync(p, files);
31+
addFilesAsync(p, files).catch(er => p.emit('error', er));
3232
return promise;
3333
};
3434
const addFilesSync = (p, files) => {
@@ -48,8 +48,7 @@ const addFilesSync = (p, files) => {
4848
p.end();
4949
};
5050
const addFilesAsync = async (p, files) => {
51-
for (let i = 0; i < files.length; i++) {
52-
const file = String(files[i]);
51+
for (const file of files) {
5352
if (file.charAt(0) === '@') {
5453
await (0, list_js_1.list)({
5554
file: node_path_1.default.resolve(String(p.cwd), file.slice(1)),
@@ -72,7 +71,7 @@ const createSync = (opt, files) => {
7271
};
7372
const createAsync = (opt, files) => {
7473
const p = new pack_js_1.Pack(opt);
75-
addFilesAsync(p, files);
74+
addFilesAsync(p, files).catch(er => p.emit('error', er));
7675
return p;
7776
};
7877
exports.create = (0, make_command_js_1.makeCommand)(createFileSync, createFile, createSync, createAsync, (_opt, files) => {

node_modules/tar/dist/commonjs/get-write-flag.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ const fs_1 = __importDefault(require("fs"));
1515
const platform = process.env.__FAKE_PLATFORM__ || process.platform;
1616
const isWindows = platform === 'win32';
1717
/* c8 ignore start */
18-
const { O_CREAT, O_TRUNC, O_WRONLY } = fs_1.default.constants;
18+
const { O_CREAT, O_NOFOLLOW, O_TRUNC, O_WRONLY } = fs_1.default.constants;
1919
const UV_FS_O_FILEMAP = Number(process.env.__FAKE_FS_O_FILENAME__) ||
2020
fs_1.default.constants.UV_FS_O_FILEMAP ||
2121
0;
2222
/* c8 ignore stop */
2323
const fMapEnabled = isWindows && !!UV_FS_O_FILEMAP;
2424
const fMapLimit = 512 * 1024;
2525
const fMapFlag = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY;
26-
exports.getWriteFlag = !fMapEnabled ?
27-
() => 'w'
28-
: (size) => (size < fMapLimit ? fMapFlag : 'w');
26+
const noFollowFlag = !isWindows && typeof O_NOFOLLOW === 'number' ?
27+
O_NOFOLLOW | O_TRUNC | O_CREAT | O_WRONLY
28+
: null;
29+
exports.getWriteFlag = noFollowFlag !== null ? () => noFollowFlag
30+
: !fMapEnabled ? () => 'w'
31+
: (size) => (size < fMapLimit ? fMapFlag : 'w');
2932
//# sourceMappingURL=get-write-flag.js.map

node_modules/tar/dist/commonjs/header.js

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ exports.Header = void 0;
4141
const node_path_1 = require("node:path");
4242
const large = __importStar(require("./large-numbers.js"));
4343
const types = __importStar(require("./types.js"));
44+
const notNegative = (n) => n === undefined || n < 0 ? undefined : n;
4445
class Header {
4546
cksumValid = false;
4647
needPax = false;
@@ -78,23 +79,44 @@ class Header {
7879
if (!buf || !(buf.length >= off + 512)) {
7980
throw new Error('need 512 bytes for header');
8081
}
81-
this.path = ex?.path ?? decString(buf, off, 100);
82-
this.mode = ex?.mode ?? gex?.mode ?? decNumber(buf, off + 100, 8);
83-
this.uid = ex?.uid ?? gex?.uid ?? decNumber(buf, off + 108, 8);
84-
this.gid = ex?.gid ?? gex?.gid ?? decNumber(buf, off + 116, 8);
85-
this.size = ex?.size ?? gex?.size ?? decNumber(buf, off + 124, 12);
82+
// Decode the typeflag (independent of any pending PAX/GNU extended header)
83+
// up front so we can tell whether THIS block is itself an intermediary
84+
// extension header (PAX `x`/`g`, GNU long-name `L`, GNU long-link `K`).
85+
// Per POSIX pax, a PAX extended header describes the *next file entry*, not
86+
// the extension headers that may sit between it and that file. Applying the
87+
// pending PAX overrides (notably `size`) to an intervening `L`/`K`/`x`/`g`
88+
// header desynchronizes the stream relative to other tar implementations
89+
// and enables tar interpretation-conflict / file-smuggling attacks.
90+
const t = decString(buf, off + 156, 1);
91+
const isNormalFS = types.normalFsTypes.has(t);
92+
const exForFields = isNormalFS ? ex : undefined;
93+
const gexForFields = isNormalFS ? gex : undefined;
94+
this.path = exForFields?.path ?? decString(buf, off, 100);
95+
this.mode =
96+
exForFields?.mode ??
97+
gexForFields?.mode ??
98+
decNumber(buf, off + 100, 8);
99+
this.uid =
100+
exForFields?.uid ?? gexForFields?.uid ?? decNumber(buf, off + 108, 8);
101+
this.gid =
102+
exForFields?.gid ?? gexForFields?.gid ?? decNumber(buf, off + 116, 8);
103+
this.size = notNegative(exForFields?.size ??
104+
gexForFields?.size ??
105+
decNumber(buf, off + 124, 12));
86106
this.mtime =
87-
ex?.mtime ?? gex?.mtime ?? decDate(buf, off + 136, 12);
107+
exForFields?.mtime ??
108+
gexForFields?.mtime ??
109+
decDate(buf, off + 136, 12);
88110
this.cksum = decNumber(buf, off + 148, 12);
89111
// if we have extended or global extended headers, apply them now
90112
// See https://github.com/npm/node-tar/pull/187
91-
// Apply global before local, so it overrides
92-
if (gex)
93-
this.#slurp(gex, true);
94-
if (ex)
95-
this.#slurp(ex);
113+
// Apply global before local, so it overrides. Never slurp the pending
114+
// extended-header fields onto an intermediary extension header.
115+
if (gexForFields)
116+
this.#slurp(gexForFields, true);
117+
if (exForFields)
118+
this.#slurp(exForFields);
96119
// old tar versions marked dirs as a file with a trailing /
97-
const t = decString(buf, off + 156, 1);
98120
if (types.isCode(t)) {
99121
this.#type = t || '0';
100122
}
@@ -110,17 +132,26 @@ class Header {
110132
this.size = 0;
111133
}
112134
this.linkpath = decString(buf, off + 157, 100);
113-
if (buf.subarray(off + 257, off + 265).toString() ===
114-
'ustar\u000000') {
135+
if (buf.subarray(off + 257, off + 265).toString() === 'ustar\u000000') {
115136
/* c8 ignore start */
116137
this.uname =
117-
ex?.uname ?? gex?.uname ?? decString(buf, off + 265, 32);
138+
exForFields?.uname ??
139+
gexForFields?.uname ??
140+
decString(buf, off + 265, 32);
118141
this.gname =
119-
ex?.gname ?? gex?.gname ?? decString(buf, off + 297, 32);
142+
exForFields?.gname ??
143+
gexForFields?.gname ??
144+
decString(buf, off + 297, 32);
120145
this.devmaj =
121-
ex?.devmaj ?? gex?.devmaj ?? decNumber(buf, off + 329, 8) ?? 0;
146+
exForFields?.devmaj ??
147+
gexForFields?.devmaj ??
148+
decNumber(buf, off + 329, 8) ??
149+
0;
122150
this.devmin =
123-
ex?.devmin ?? gex?.devmin ?? decNumber(buf, off + 337, 8) ?? 0;
151+
exForFields?.devmin ??
152+
gexForFields?.devmin ??
153+
decNumber(buf, off + 337, 8) ??
154+
0;
124155
/* c8 ignore stop */
125156
if (buf[off + 475] !== 0) {
126157
// definitely a prefix, definitely >130 chars.
@@ -133,10 +164,8 @@ class Header {
133164
this.path = prefix + '/' + this.path;
134165
}
135166
/* c8 ignore start */
136-
this.atime =
137-
ex?.atime ?? gex?.atime ?? decDate(buf, off + 476, 12);
138-
this.ctime =
139-
ex?.ctime ?? gex?.ctime ?? decDate(buf, off + 488, 12);
167+
this.atime = ex?.atime ?? gex?.atime ?? decDate(buf, off + 476, 12);
168+
this.ctime = ex?.ctime ?? gex?.ctime ?? decDate(buf, off + 488, 12);
140169
/* c8 ignore stop */
141170
}
142171
}
@@ -159,6 +188,7 @@ class Header {
159188
// null/undefined values are ignored.
160189
return !(v === null ||
161190
v === undefined ||
191+
(k === 'size' && Number(v) < 0) ||
162192
(k === 'path' && gex) ||
163193
(k === 'linkpath' && gex) ||
164194
k === 'global');
@@ -180,17 +210,12 @@ class Header {
180210
const prefix = split[1];
181211
this.needPax = !!split[2];
182212
this.needPax = encString(buf, off, 100, path) || this.needPax;
183-
this.needPax =
184-
encNumber(buf, off + 100, 8, this.mode) || this.needPax;
185-
this.needPax =
186-
encNumber(buf, off + 108, 8, this.uid) || this.needPax;
187-
this.needPax =
188-
encNumber(buf, off + 116, 8, this.gid) || this.needPax;
189-
this.needPax =
190-
encNumber(buf, off + 124, 12, this.size) || this.needPax;
191-
this.needPax =
192-
encDate(buf, off + 136, 12, this.mtime) || this.needPax;
193-
buf[off + 156] = this.#type.charCodeAt(0);
213+
this.needPax = encNumber(buf, off + 100, 8, this.mode) || this.needPax;
214+
this.needPax = encNumber(buf, off + 108, 8, this.uid) || this.needPax;
215+
this.needPax = encNumber(buf, off + 116, 8, this.gid) || this.needPax;
216+
this.needPax = encNumber(buf, off + 124, 12, this.size) || this.needPax;
217+
this.needPax = encDate(buf, off + 136, 12, this.mtime) || this.needPax;
218+
buf[off + 156] = Number(this.#type.codePointAt(0));
194219
this.needPax =
195220
encString(buf, off + 157, 100, this.linkpath) || this.needPax;
196221
buf.write('ustar\u000000', off + 257, 8);
@@ -205,12 +230,10 @@ class Header {
205230
this.needPax =
206231
encString(buf, off + 345, prefixSize, prefix) || this.needPax;
207232
if (buf[off + 475] !== 0) {
208-
this.needPax =
209-
encString(buf, off + 345, 155, prefix) || this.needPax;
233+
this.needPax = encString(buf, off + 345, 155, prefix) || this.needPax;
210234
}
211235
else {
212-
this.needPax =
213-
encString(buf, off + 345, 130, prefix) || this.needPax;
236+
this.needPax = encString(buf, off + 345, 130, prefix) || this.needPax;
214237
this.needPax =
215238
encDate(buf, off + 476, 12, this.atime) || this.needPax;
216239
this.needPax =

node_modules/tar/dist/commonjs/index.min.js

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

node_modules/tar/dist/commonjs/list.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,22 @@ const onReadEntryFunction = (opt) => {
5959
const filesFilter = (opt, files) => {
6060
const map = new Map(files.map(f => [(0, strip_trailing_slashes_js_1.stripTrailingSlashes)(f), true]));
6161
const filter = opt.filter;
62-
const mapHas = (file, r = '') => {
62+
// limit recursion to 100 levels
63+
const MAX = 100;
64+
const mapHas = (file, r = '', depth = 0) => {
65+
/* c8 ignore start - excessive caution */
66+
if (depth >= MAX) {
67+
map.set(file, false);
68+
return false;
69+
}
70+
/* c8 ignore stop */
6371
const root = r || (0, path_1.parse)(file).root || '.';
6472
let ret;
6573
if (file === root)
6674
ret = false;
6775
else {
6876
const m = map.get(file);
69-
if (m !== undefined) {
70-
ret = m;
71-
}
72-
else {
73-
ret = mapHas((0, path_1.dirname)(file), root);
74-
}
77+
ret = m !== undefined ? m : mapHas((0, path_1.dirname)(file), root, depth + 1);
7578
}
7679
map.set(file, ret);
7780
return ret;
@@ -114,7 +117,7 @@ const listFileSync = (opt) => {
114117
node_fs_1.default.closeSync(fd);
115118
/* c8 ignore next */
116119
}
117-
catch (er) { }
120+
catch { }
118121
}
119122
}
120123
};

node_modules/tar/dist/commonjs/make-command.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ const makeCommand = (syncFile, asyncFile, syncNoFile, asyncNoFile, validate) =>
1212
cb = entries;
1313
entries = undefined;
1414
}
15-
if (!entries) {
16-
entries = [];
17-
}
18-
else {
19-
entries = Array.from(entries);
20-
}
15+
entries = !entries ? [] : Array.from(entries);
2116
const opt = (0, options_js_1.dealias)(opt_);
2217
validate?.(opt, entries);
2318
if ((0, options_js_1.isSyncFile)(opt)) {
@@ -28,9 +23,7 @@ const makeCommand = (syncFile, asyncFile, syncNoFile, asyncNoFile, validate) =>
2823
}
2924
else if ((0, options_js_1.isAsyncFile)(opt)) {
3025
const p = asyncFile(opt, entries);
31-
// weirdness to make TS happy
32-
const c = cb ? cb : undefined;
33-
return c ? p.then(() => c(), c) : p;
26+
return cb ? p.then(() => cb(), cb) : p;
3427
}
3528
else if ((0, options_js_1.isSyncNoFile)(opt)) {
3629
if (typeof cb === 'function') {
@@ -45,9 +38,7 @@ const makeCommand = (syncFile, asyncFile, syncNoFile, asyncNoFile, validate) =>
4538
return asyncNoFile(opt, entries);
4639
/* c8 ignore start */
4740
}
48-
else {
49-
throw new Error('impossible options??');
50-
}
41+
throw new Error('impossible options??');
5142
/* c8 ignore stop */
5243
}, {
5344
syncFile,

node_modules/tar/dist/commonjs/mkdir.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const mkdir = (dir, opt, cb) => {
7272
};
7373
exports.mkdir = mkdir;
7474
const mkdir_ = (base, parts, mode, unlink, cwd, created, cb) => {
75-
if (!parts.length) {
75+
if (parts.length === 0) {
7676
return cb(null, created);
7777
}
7878
const p = parts.shift();
@@ -83,8 +83,7 @@ const onmkdir = (part, parts, mode, unlink, cwd, created, cb) => (er) => {
8383
if (er) {
8484
node_fs_1.default.lstat(part, (statEr, st) => {
8585
if (statEr) {
86-
statEr.path =
87-
statEr.path && (0, normalize_windows_path_js_1.normalizeWindowsPath)(statEr.path);
86+
statEr.path = statEr.path && (0, normalize_windows_path_js_1.normalizeWindowsPath)(statEr.path);
8887
cb(statEr);
8988
}
9089
else if (st.isDirectory()) {
@@ -113,7 +112,7 @@ const onmkdir = (part, parts, mode, unlink, cwd, created, cb) => (er) => {
113112
};
114113
const checkCwdSync = (dir) => {
115114
let ok = false;
116-
let code = undefined;
115+
let code;
117116
try {
118117
ok = node_fs_1.default.statSync(dir).isDirectory();
119118
}
@@ -159,14 +158,14 @@ const mkdirSync = (dir, opt) => {
159158
}
160159
const sub = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.relative(cwd, dir));
161160
const parts = sub.split('/');
162-
let created = undefined;
161+
let created;
163162
for (let p = parts.shift(), part = cwd; p && (part += '/' + p); p = parts.shift()) {
164163
part = (0, normalize_windows_path_js_1.normalizeWindowsPath)(node_path_1.default.resolve(part));
165164
try {
166165
node_fs_1.default.mkdirSync(part, mode);
167166
created = created || part;
168167
}
169-
catch (er) {
168+
catch {
170169
const st = node_fs_1.default.lstatSync(part);
171170
if (st.isDirectory()) {
172171
continue;

node_modules/tar/dist/commonjs/normalize-windows-path.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
77
exports.normalizeWindowsPath = void 0;
88
const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
99
exports.normalizeWindowsPath = platform !== 'win32' ?
10-
(p) => p
11-
: (p) => p && p.replace(/\\/g, '/');
10+
(p) => String(p)
11+
: (p) => String(p).replaceAll(/\\/g, '/');
1212
//# sourceMappingURL=normalize-windows-path.js.map

0 commit comments

Comments
 (0)