Skip to content

Commit e773c77

Browse files
author
Michael Smith
committed
1 parent f05f6af commit e773c77

15 files changed

Lines changed: 168 additions & 48 deletions

‎node_modules/tar/dist/commonjs/header.js‎

Lines changed: 5 additions & 4 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;
@@ -99,10 +100,9 @@ class Header {
99100
exForFields?.uid ?? gexForFields?.uid ?? decNumber(buf, off + 108, 8);
100101
this.gid =
101102
exForFields?.gid ?? gexForFields?.gid ?? decNumber(buf, off + 116, 8);
102-
this.size =
103-
exForFields?.size ??
104-
gexForFields?.size ??
105-
decNumber(buf, off + 124, 12);
103+
this.size = notNegative(exForFields?.size ??
104+
gexForFields?.size ??
105+
decNumber(buf, off + 124, 12));
106106
this.mtime =
107107
exForFields?.mtime ??
108108
gexForFields?.mtime ??
@@ -188,6 +188,7 @@ class Header {
188188
// null/undefined values are ignored.
189189
return !(v === null ||
190190
v === undefined ||
191+
(k === 'size' && Number(v) < 0) ||
191192
(k === 'path' && gex) ||
192193
(k === 'linkpath' && gex) ||
193194
k === 'global');

‎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/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.replaceAll(/\\/g, '/');
10+
(p) => String(p)
11+
: (p) => String(p).replaceAll(/\\/g, '/');
1212
//# sourceMappingURL=normalize-windows-path.js.map

‎node_modules/tar/dist/commonjs/parse.js‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ const SAW_VALID_ENTRY = Symbol('sawValidEntry');
6060
const SAW_NULL_BLOCK = Symbol('sawNullBlock');
6161
const SAW_EOF = Symbol('sawEOF');
6262
const CLOSESTREAM = Symbol('closeStream');
63+
const MAX_DECOMPRESSION_RATIO = 1000;
64+
const COMPRESSEDBYTESREAD = Symbol('compressedBytesRead');
65+
const DECOMPRESSEDBYTESREAD = Symbol('decompressedBytesRead');
66+
const CHECKDECOMPRESSIONRATIO = Symbol('checkDecompressionRatio');
6367
const noop = () => true;
6468
class Parser extends events_1.EventEmitter {
6569
file;
@@ -68,6 +72,7 @@ class Parser extends events_1.EventEmitter {
6872
filter;
6973
brotli;
7074
zstd;
75+
maxDecompressionRatio;
7176
writable = true;
7277
readable = false;
7378
[QUEUE] = [];
@@ -87,6 +92,8 @@ class Parser extends events_1.EventEmitter {
8792
[WRITING] = false;
8893
[CONSUMING] = false;
8994
[EMITTEDEND] = false;
95+
[COMPRESSEDBYTESREAD] = 0;
96+
[DECOMPRESSEDBYTESREAD] = 0;
9097
constructor(opt = {}) {
9198
super();
9299
this.file = opt.file || '';
@@ -109,6 +116,10 @@ class Parser extends events_1.EventEmitter {
109116
});
110117
}
111118
this.strict = !!opt.strict;
119+
this.maxDecompressionRatio =
120+
typeof opt.maxDecompressionRatio === 'number' ?
121+
opt.maxDecompressionRatio
122+
: MAX_DECOMPRESSION_RATIO;
112123
this.maxMetaEntrySize = opt.maxMetaEntrySize || maxMetaEntrySize;
113124
this.filter = typeof opt.filter === 'function' ? opt.filter : noop;
114125
// Unlike gzip, brotli doesn't have any magic bytes to identify it
@@ -362,11 +373,23 @@ class Parser extends events_1.EventEmitter {
362373
}
363374
}
364375
abort(error) {
376+
if (this[ABORTED]) {
377+
return;
378+
}
365379
this[ABORTED] = true;
366380
this.emit('abort', error);
367381
// always throws, even in non-strict mode
368382
this.warn('TAR_ABORT', error, { recoverable: false });
369383
}
384+
[CHECKDECOMPRESSIONRATIO](chunk) {
385+
this[DECOMPRESSEDBYTESREAD] += chunk.length;
386+
const ratio = this[DECOMPRESSEDBYTESREAD] / this[COMPRESSEDBYTESREAD];
387+
if (ratio > this.maxDecompressionRatio) {
388+
this.abort(new Error(`max decompression ratio exceeded: ${ratio.toFixed(2)} > ${this.maxDecompressionRatio}`));
389+
return false;
390+
}
391+
return true;
392+
}
370393
write(chunk, encoding, cb) {
371394
if (typeof encoding === 'function') {
372395
cb = encoding;
@@ -450,13 +473,22 @@ class Parser extends events_1.EventEmitter {
450473
this[UNZIP] === undefined ? new minizlib_1.Unzip({})
451474
: isZstd ? new minizlib_1.ZstdDecompress({})
452475
: new minizlib_1.BrotliDecompress({});
453-
this[UNZIP].on('data', chunk => this[CONSUMECHUNK](chunk));
454-
this[UNZIP].on('error', er => this.abort(er));
476+
this[UNZIP].on('data', chunk => {
477+
if (this[CHECKDECOMPRESSIONRATIO](chunk)) {
478+
this[CONSUMECHUNK](chunk);
479+
}
480+
});
481+
this[UNZIP].on('error', er => {
482+
if (!this[ABORTED]) {
483+
this.abort(er);
484+
}
485+
});
455486
this[UNZIP].on('end', () => {
456487
this[ENDED] = true;
457488
this[CONSUMECHUNK]();
458489
});
459490
this[WRITING] = true;
491+
this[COMPRESSEDBYTESREAD] += chunk.length;
460492
const ret = !!this[UNZIP][ended ? 'end' : 'write'](chunk);
461493
this[WRITING] = false;
462494
cb?.();
@@ -465,6 +497,7 @@ class Parser extends events_1.EventEmitter {
465497
}
466498
this[WRITING] = true;
467499
if (this[UNZIP]) {
500+
this[COMPRESSEDBYTESREAD] += chunk.length;
468501
this[UNZIP].write(chunk);
469502
}
470503
else {
@@ -495,7 +528,7 @@ class Parser extends events_1.EventEmitter {
495528
!this[CONSUMING]) {
496529
this[EMITTEDEND] = true;
497530
const entry = this[WRITEENTRY];
498-
if (entry && entry.blockRemain) {
531+
if (entry?.blockRemain) {
499532
// truncated, likely a damaged file
500533
const have = this[BUFFER] ? this[BUFFER].length : 0;
501534
this.warn('TAR_BAD_ARCHIVE', `Truncated input (needed ${entry.blockRemain} more bytes, only ${have} available)`, { entry });
@@ -589,8 +622,10 @@ class Parser extends events_1.EventEmitter {
589622
if (!this[ABORTED]) {
590623
if (this[UNZIP]) {
591624
/* c8 ignore start */
592-
if (chunk)
625+
if (chunk) {
626+
this[COMPRESSEDBYTESREAD] += chunk.length;
593627
this[UNZIP].write(chunk);
628+
}
594629
/* c8 ignore stop */
595630
this[UNZIP].end();
596631
}

‎node_modules/tar/dist/commonjs/pax.js‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,36 @@ const parseKVLine = (set, line) => {
147147
return set;
148148
}
149149
const k = r.replace(/^SCHILY\.(dev|ino|nlink)/, '$1');
150-
const v = kv.join('=');
151-
set[k] =
152-
/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(k) ?
153-
new Date(Number(v) * 1000)
154-
: /^[0-9]+$/.test(v) ? +v
155-
: v;
150+
const v = kv.join('=').replace(/\0.*/, '');
151+
switch (k) {
152+
case 'path':
153+
case 'linkpath':
154+
case 'type':
155+
case 'charset':
156+
case 'comment':
157+
case 'gname':
158+
case 'uname':
159+
set[k] = v;
160+
break;
161+
case 'ctime':
162+
case 'atime':
163+
case 'mtime':
164+
set[k] = new Date(Number(v) * 1000);
165+
break;
166+
case 'size':
167+
const s = +v;
168+
if (s >= 0)
169+
set[k] = s;
170+
break;
171+
case 'gid':
172+
case 'uid':
173+
case 'dev':
174+
case 'ino':
175+
case 'nlink':
176+
case 'mode':
177+
set[k] = +v;
178+
break;
179+
}
156180
return set;
157181
};
158182
//# sourceMappingURL=pax.js.map

‎node_modules/tar/dist/commonjs/unpack.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class Unpack extends parse_js_1.Parser {
185185
// default true for root
186186
this.preserveOwner =
187187
opt.preserveOwner === undefined && typeof opt.uid !== 'number' ?
188-
!!(process.getuid && process.getuid() === 0)
188+
!!(process.getuid?.() === 0)
189189
: !!opt.preserveOwner;
190190
this.processUid =
191191
(this.preserveOwner || this.setOwner) && process.getuid ?
@@ -406,7 +406,7 @@ class Unpack extends parse_js_1.Parser {
406406
}
407407
}
408408
[MKDIR](dir, mode, cb) {
409-
(0, mkdir_js_1.mkdir)((0, normalize_windows_path_js_1.normalizeWindowsPath)(dir), {
409+
void (0, mkdir_js_1.mkdir)((0, normalize_windows_path_js_1.normalizeWindowsPath)(dir), {
410410
uid: this.uid,
411411
gid: this.gid,
412412
processUid: this.processUid,

‎node_modules/tar/dist/esm/header.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { posix as pathModule } from 'node:path';
66
import * as large from './large-numbers.js';
77
import * as types from './types.js';
8+
const notNegative = (n) => n === undefined || n < 0 ? undefined : n;
89
export class Header {
910
cksumValid = false;
1011
needPax = false;
@@ -63,10 +64,9 @@ export class Header {
6364
exForFields?.uid ?? gexForFields?.uid ?? decNumber(buf, off + 108, 8);
6465
this.gid =
6566
exForFields?.gid ?? gexForFields?.gid ?? decNumber(buf, off + 116, 8);
66-
this.size =
67-
exForFields?.size ??
68-
gexForFields?.size ??
69-
decNumber(buf, off + 124, 12);
67+
this.size = notNegative(exForFields?.size ??
68+
gexForFields?.size ??
69+
decNumber(buf, off + 124, 12));
7070
this.mtime =
7171
exForFields?.mtime ??
7272
gexForFields?.mtime ??
@@ -152,6 +152,7 @@ export class Header {
152152
// null/undefined values are ignored.
153153
return !(v === null ||
154154
v === undefined ||
155+
(k === 'size' && Number(v) < 0) ||
155156
(k === 'path' && gex) ||
156157
(k === 'linkpath' && gex) ||
157158
k === 'global');

‎node_modules/tar/dist/esm/index.min.js‎

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

‎node_modules/tar/dist/esm/normalize-windows-path.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
// so that we can use / as our one and only directory separator char.
55
const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
66
export const normalizeWindowsPath = platform !== 'win32' ?
7-
(p) => p
8-
: (p) => p && p.replaceAll(/\\/g, '/');
7+
(p) => String(p)
8+
: (p) => String(p).replaceAll(/\\/g, '/');
99
//# sourceMappingURL=normalize-windows-path.js.map

‎node_modules/tar/dist/esm/parse.js‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ const SAW_VALID_ENTRY = Symbol('sawValidEntry');
5757
const SAW_NULL_BLOCK = Symbol('sawNullBlock');
5858
const SAW_EOF = Symbol('sawEOF');
5959
const CLOSESTREAM = Symbol('closeStream');
60+
const MAX_DECOMPRESSION_RATIO = 1000;
61+
const COMPRESSEDBYTESREAD = Symbol('compressedBytesRead');
62+
const DECOMPRESSEDBYTESREAD = Symbol('decompressedBytesRead');
63+
const CHECKDECOMPRESSIONRATIO = Symbol('checkDecompressionRatio');
6064
const noop = () => true;
6165
export class Parser extends EE {
6266
file;
@@ -65,6 +69,7 @@ export class Parser extends EE {
6569
filter;
6670
brotli;
6771
zstd;
72+
maxDecompressionRatio;
6873
writable = true;
6974
readable = false;
7075
[QUEUE] = [];
@@ -84,6 +89,8 @@ export class Parser extends EE {
8489
[WRITING] = false;
8590
[CONSUMING] = false;
8691
[EMITTEDEND] = false;
92+
[COMPRESSEDBYTESREAD] = 0;
93+
[DECOMPRESSEDBYTESREAD] = 0;
8794
constructor(opt = {}) {
8895
super();
8996
this.file = opt.file || '';
@@ -106,6 +113,10 @@ export class Parser extends EE {
106113
});
107114
}
108115
this.strict = !!opt.strict;
116+
this.maxDecompressionRatio =
117+
typeof opt.maxDecompressionRatio === 'number' ?
118+
opt.maxDecompressionRatio
119+
: MAX_DECOMPRESSION_RATIO;
109120
this.maxMetaEntrySize = opt.maxMetaEntrySize || maxMetaEntrySize;
110121
this.filter = typeof opt.filter === 'function' ? opt.filter : noop;
111122
// Unlike gzip, brotli doesn't have any magic bytes to identify it
@@ -359,11 +370,23 @@ export class Parser extends EE {
359370
}
360371
}
361372
abort(error) {
373+
if (this[ABORTED]) {
374+
return;
375+
}
362376
this[ABORTED] = true;
363377
this.emit('abort', error);
364378
// always throws, even in non-strict mode
365379
this.warn('TAR_ABORT', error, { recoverable: false });
366380
}
381+
[CHECKDECOMPRESSIONRATIO](chunk) {
382+
this[DECOMPRESSEDBYTESREAD] += chunk.length;
383+
const ratio = this[DECOMPRESSEDBYTESREAD] / this[COMPRESSEDBYTESREAD];
384+
if (ratio > this.maxDecompressionRatio) {
385+
this.abort(new Error(`max decompression ratio exceeded: ${ratio.toFixed(2)} > ${this.maxDecompressionRatio}`));
386+
return false;
387+
}
388+
return true;
389+
}
367390
write(chunk, encoding, cb) {
368391
if (typeof encoding === 'function') {
369392
cb = encoding;
@@ -447,13 +470,22 @@ export class Parser extends EE {
447470
this[UNZIP] === undefined ? new Unzip({})
448471
: isZstd ? new ZstdDecompress({})
449472
: new BrotliDecompress({});
450-
this[UNZIP].on('data', chunk => this[CONSUMECHUNK](chunk));
451-
this[UNZIP].on('error', er => this.abort(er));
473+
this[UNZIP].on('data', chunk => {
474+
if (this[CHECKDECOMPRESSIONRATIO](chunk)) {
475+
this[CONSUMECHUNK](chunk);
476+
}
477+
});
478+
this[UNZIP].on('error', er => {
479+
if (!this[ABORTED]) {
480+
this.abort(er);
481+
}
482+
});
452483
this[UNZIP].on('end', () => {
453484
this[ENDED] = true;
454485
this[CONSUMECHUNK]();
455486
});
456487
this[WRITING] = true;
488+
this[COMPRESSEDBYTESREAD] += chunk.length;
457489
const ret = !!this[UNZIP][ended ? 'end' : 'write'](chunk);
458490
this[WRITING] = false;
459491
cb?.();
@@ -462,6 +494,7 @@ export class Parser extends EE {
462494
}
463495
this[WRITING] = true;
464496
if (this[UNZIP]) {
497+
this[COMPRESSEDBYTESREAD] += chunk.length;
465498
this[UNZIP].write(chunk);
466499
}
467500
else {
@@ -492,7 +525,7 @@ export class Parser extends EE {
492525
!this[CONSUMING]) {
493526
this[EMITTEDEND] = true;
494527
const entry = this[WRITEENTRY];
495-
if (entry && entry.blockRemain) {
528+
if (entry?.blockRemain) {
496529
// truncated, likely a damaged file
497530
const have = this[BUFFER] ? this[BUFFER].length : 0;
498531
this.warn('TAR_BAD_ARCHIVE', `Truncated input (needed ${entry.blockRemain} more bytes, only ${have} available)`, { entry });
@@ -586,8 +619,10 @@ export class Parser extends EE {
586619
if (!this[ABORTED]) {
587620
if (this[UNZIP]) {
588621
/* c8 ignore start */
589-
if (chunk)
622+
if (chunk) {
623+
this[COMPRESSEDBYTESREAD] += chunk.length;
590624
this[UNZIP].write(chunk);
625+
}
591626
/* c8 ignore stop */
592627
this[UNZIP].end();
593628
}

0 commit comments

Comments
 (0)