@vltpkg/tar 1.0.3 → 1.0.4
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 +8 -0
- package/dist/unpack.js +28 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -83,6 +83,14 @@ by default (with the same windows/umask caveats as files, so maybe
|
|
|
83
83
|
that's `0o775` or some such.) All ctime/mtime/atime/birthtime values
|
|
84
84
|
will just be left as the current time.
|
|
85
85
|
|
|
86
|
+
Gzip-compressed tarballs are inflated with a size bound before any tar
|
|
87
|
+
structure checks run. The cap is the smaller of 2 GiB and 1000 times
|
|
88
|
+
the compressed size (the same 1000:1 ratio node-tar and npm use).
|
|
89
|
+
Exceeding it fails with `tarball exceeds maximum unpacked size` rather
|
|
90
|
+
than allocating the decompressed buffer. Raise the ceiling with
|
|
91
|
+
`VLT_TAR_MAX_UNPACKED_BYTES` if a legitimate package is larger than 2
|
|
92
|
+
GiB unpacked.
|
|
93
|
+
|
|
86
94
|
It does not do any of the binary linking or other stuff that a package
|
|
87
95
|
manager will need to do. It _just_ does the unpack, as ruthlessly fast
|
|
88
96
|
as possible, and that's all.
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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.
|
|
4
|
+
"version": "1.0.4",
|
|
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.
|
|
17
|
-
"@vltpkg/types": "1.0.
|
|
16
|
+
"@vltpkg/error-cause": "1.0.4",
|
|
17
|
+
"@vltpkg/types": "1.0.4",
|
|
18
18
|
"rimraf": "^6.1.2",
|
|
19
19
|
"tar": "^7.5.2"
|
|
20
20
|
},
|