@vltpkg/registry-client 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.
@@ -25,6 +25,17 @@ import { inspect } from 'node:util';
25
25
  import { gunzipSync } from 'node:zlib';
26
26
  import { getRawHeader, setRawHeader } from "./raw-header.js";
27
27
  import { getDecodedValue, getEncondedValue, } from "./string-encoding.js";
28
+ // same bound as @vltpkg/tar unpack: reject decompression bombs
29
+ // rather than committing unbounded memory to gunzipSync.
30
+ const MAX_DECOMPRESSION_RATIO = 1000;
31
+ const defaultMaxUnpackedBytes = 2 * 1024 * 1024 * 1024;
32
+ const parseMaxUnpackedBytes = (raw) => {
33
+ const n = Number(raw);
34
+ return Number.isFinite(n) && n >= 1 ?
35
+ Math.floor(n)
36
+ : defaultMaxUnpackedBytes;
37
+ };
38
+ const maxUnpackedBytes = parseMaxUnpackedBytes(process.env.VLT_TAR_MAX_UNPACKED_BYTES);
28
39
  const readSize = (buf, offset) => {
29
40
  const a = buf[offset];
30
41
  const b = buf[offset + 1];
@@ -389,7 +400,21 @@ export class CacheEntry {
389
400
  if (this._body.length === 0)
390
401
  throw error('Invalid buffer, cant unzip');
391
402
  /* c8 ignore stop */
392
- const b = gunzipSync(this._body);
403
+ const max = Math.min(maxUnpackedBytes, this._body.length * MAX_DECOMPRESSION_RATIO);
404
+ let b;
405
+ try {
406
+ b = gunzipSync(this._body, { maxOutputLength: max });
407
+ }
408
+ catch (er) {
409
+ throw (er.code ===
410
+ 'ERR_BUFFER_TOO_LARGE') ?
411
+ error('cache entry exceeds maximum unpacked size', {
412
+ found: this._body.length,
413
+ max,
414
+ cause: er,
415
+ })
416
+ : er;
417
+ }
393
418
  this.setHeader('content-encoding', 'identity');
394
419
  const u8 = new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
395
420
  this.#body = u8;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/registry-client",
3
3
  "description": "Fetch package artifacts and metadata from registries",
4
- "version": "1.0.3",
4
+ "version": "1.0.4",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -13,14 +13,14 @@
13
13
  "url": "http://vlt.sh"
14
14
  },
15
15
  "dependencies": {
16
- "@vltpkg/cache": "1.0.3",
17
- "@vltpkg/cache-unzip": "1.0.3",
18
- "@vltpkg/error-cause": "1.0.3",
19
- "@vltpkg/keychain": "1.0.3",
20
- "@vltpkg/output": "1.0.3",
21
- "@vltpkg/types": "1.0.3",
22
- "@vltpkg/url-open": "1.0.3",
23
- "@vltpkg/xdg": "1.0.3",
16
+ "@vltpkg/cache": "1.0.4",
17
+ "@vltpkg/cache-unzip": "1.0.4",
18
+ "@vltpkg/error-cause": "1.0.4",
19
+ "@vltpkg/keychain": "1.0.4",
20
+ "@vltpkg/output": "1.0.4",
21
+ "@vltpkg/types": "1.0.4",
22
+ "@vltpkg/url-open": "1.0.4",
23
+ "@vltpkg/xdg": "1.0.4",
24
24
  "cache-control-parser": "^2.0.6",
25
25
  "package-json-from-dist": "^1.0.1",
26
26
  "undici": "^7.16.0"