@vltpkg/tar 1.0.3 → 1.0.5

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 CHANGED
@@ -61,8 +61,9 @@ Queue of requests awaiting an available worker.
61
61
 
62
62
  #### `pool.pending`
63
63
 
64
- Unpack requests that have been assigned to a worker, but not yet
65
- completed.
64
+ All unpack requests that have not yet completed, both those currently
65
+ assigned to a worker and those still waiting in the queue. Entries are
66
+ removed once the request resolves or rejects.
66
67
 
67
68
  #### `pool.unpack(tarData: Buffer, target: string) => Promise<void>`
68
69
 
@@ -83,6 +84,14 @@ by default (with the same windows/umask caveats as files, so maybe
83
84
  that's `0o775` or some such.) All ctime/mtime/atime/birthtime values
84
85
  will just be left as the current time.
85
86
 
87
+ Gzip-compressed tarballs are inflated with a size bound before any tar
88
+ structure checks run. The cap is the smaller of 2 GiB and 1000 times
89
+ the compressed size (the same 1000:1 ratio node-tar and npm use).
90
+ Exceeding it fails with `tarball exceeds maximum unpacked size` rather
91
+ than allocating the decompressed buffer. Raise the ceiling with
92
+ `VLT_TAR_MAX_UNPACKED_BYTES` if a legitimate package is larger than 2
93
+ GiB unpacked.
94
+
86
95
  It does not do any of the binary linking or other stuff that a package
87
96
  manager will need to do. It _just_ does the unpack, as ruthlessly fast
88
97
  as possible, and that's all.
package/dist/pool.d.ts CHANGED
@@ -12,8 +12,8 @@ export * from './worker.ts';
12
12
  export declare class Pool {
13
13
  #private;
14
14
  /**
15
- * Number of workers to emplly. Defaults to 1 less than the number of
16
- * CPUs, or 1.
15
+ * Number of workers to employ. Defaults to 8 times one less than
16
+ * the number of available CPUs, with a minimum of 8.
17
17
  */
18
18
  jobs: number;
19
19
  /**
@@ -25,8 +25,10 @@ export declare class Pool {
25
25
  */
26
26
  queue: UnpackRequest[];
27
27
  /**
28
- * Requests that have been assigned to a worker, but have not yet
29
- * been confirmed completed.
28
+ * All requests that have not yet been confirmed completed, both
29
+ * those currently assigned to a worker and those still waiting in
30
+ * the queue. Entries are removed once the request resolves or
31
+ * rejects, releasing the reference to its tarball buffer.
30
32
  */
31
33
  pending: Map<number, UnpackRequest>;
32
34
  /**
package/dist/pool.js CHANGED
@@ -14,8 +14,8 @@ export * from "./worker.js";
14
14
  */
15
15
  export class Pool {
16
16
  /**
17
- * Number of workers to emplly. Defaults to 1 less than the number of
18
- * CPUs, or 1.
17
+ * Number of workers to employ. Defaults to 8 times one less than
18
+ * the number of available CPUs, with a minimum of 8.
19
19
  */
20
20
  /* c8 ignore next */
21
21
  jobs = 8 * (Math.max(os.availableParallelism(), 2) - 1);
@@ -28,8 +28,10 @@ export class Pool {
28
28
  */
29
29
  queue = [];
30
30
  /**
31
- * Requests that have been assigned to a worker, but have not yet
32
- * been confirmed completed.
31
+ * All requests that have not yet been confirmed completed, both
32
+ * those currently assigned to a worker and those still waiting in
33
+ * the queue. Entries are removed once the request resolves or
34
+ * rejects, releasing the reference to its tarball buffer.
33
35
  */
34
36
  pending = new Map();
35
37
  // handle a message from the worker
@@ -41,6 +43,8 @@ export class Pool {
41
43
  /* c8 ignore next */
42
44
  if (!ur)
43
45
  return;
46
+ // request is done, stop holding its tarball buffer in memory
47
+ this.pending.delete(id);
44
48
  if (isResponseOK(m)) {
45
49
  ur.resolve();
46
50
  /* c8 ignore start - nearly impossible in normal circumstances */
package/dist/unpack.js CHANGED
@@ -7,9 +7,34 @@ import { Header } from 'tar/header';
7
7
  import { Pax } from 'tar/pax';
8
8
  import { unzip as unzipCB } from 'node:zlib';
9
9
  import { findTarDir } from "./find-tar-dir.js";
10
- const unzip = async (input) => new Promise((res, rej) =>
11
- /* c8 ignore start */
12
- unzipCB(input, (er, result) => (er ? rej(er) : res(result))));
10
+ // Matches node-tar's MAX_DECOMPRESSION_RATIO, which npm uses via pacote.
11
+ const MAX_DECOMPRESSION_RATIO = 1000;
12
+ // node-tar streams, so its ratio alone bounds peak memory. We inflate into
13
+ // a single Buffer, so without a ceiling a large tarball still commits
14
+ // ratio * compressed bytes.
15
+ const defaultMaxUnpackedBytes = 2 * 1024 * 1024 * 1024;
16
+ const parseMaxUnpackedBytes = (raw) => {
17
+ const n = Number(raw);
18
+ return Number.isFinite(n) && n >= 1 ?
19
+ Math.floor(n)
20
+ : defaultMaxUnpackedBytes;
21
+ };
22
+ const maxUnpackedBytes = parseMaxUnpackedBytes(process.env.VLT_TAR_MAX_UNPACKED_BYTES);
23
+ const unzip = async (input) => {
24
+ const max = Math.min(maxUnpackedBytes, input.length * MAX_DECOMPRESSION_RATIO);
25
+ return new Promise((res, rej) => unzipCB(input, { maxOutputLength: max }, (er, result) => {
26
+ if (!er)
27
+ return res(result);
28
+ return rej((er.code ===
29
+ 'ERR_BUFFER_TOO_LARGE') ?
30
+ error('tarball exceeds maximum unpacked size', {
31
+ found: input.length,
32
+ max,
33
+ cause: er,
34
+ })
35
+ : er);
36
+ }));
37
+ };
13
38
  const exists = async (path) => {
14
39
  try {
15
40
  await lstat(path);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/tar",
3
3
  "description": "An extremely limited and very fast tar extractor",
4
- "version": "1.0.3",
4
+ "version": "1.0.5",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -13,8 +13,8 @@
13
13
  "url": "http://vlt.sh"
14
14
  },
15
15
  "dependencies": {
16
- "@vltpkg/error-cause": "1.0.3",
17
- "@vltpkg/types": "1.0.3",
16
+ "@vltpkg/error-cause": "1.0.5",
17
+ "@vltpkg/types": "1.0.5",
18
18
  "rimraf": "^6.1.2",
19
19
  "tar": "^7.5.2"
20
20
  },