tar 4.4.8 → 4.4.9

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.
Files changed (2) hide show
  1. package/lib/large-numbers.js +32 -27
  2. package/package.json +12 -8
@@ -1,12 +1,13 @@
1
1
  'use strict'
2
2
  // Tar can encode large and negative numbers using a leading byte of
3
- // 0xff for negative, and 0x80 for positive. The trailing byte in the
4
- // section will always be 0x20, or in some implementations 0x00.
5
- // this module encodes and decodes these things.
3
+ // 0xff for negative, and 0x80 for positive.
6
4
 
7
5
  const encode = exports.encode = (num, buf) => {
8
- buf[buf.length - 1] = 0x20
9
- if (num < 0)
6
+ if (!Number.isSafeInteger(num))
7
+ // The number is so large that javascript cannot represent it with integer
8
+ // precision.
9
+ throw TypeError('cannot encode number outside of javascript safe integer range')
10
+ else if (num < 0)
10
11
  encodeNegative(num, buf)
11
12
  else
12
13
  encodePositive(num, buf)
@@ -15,13 +16,10 @@ const encode = exports.encode = (num, buf) => {
15
16
 
16
17
  const encodePositive = (num, buf) => {
17
18
  buf[0] = 0x80
18
- for (var i = buf.length - 2; i > 0; i--) {
19
- if (num === 0)
20
- buf[i] = 0
21
- else {
22
- buf[i] = num % 0x100
23
- num = Math.floor(num / 0x100)
24
- }
19
+
20
+ for (var i = buf.length; i > 1; i--) {
21
+ buf[i-1] = num & 0xff
22
+ num = Math.floor(num / 0x100)
25
23
  }
26
24
  }
27
25
 
@@ -29,21 +27,16 @@ const encodeNegative = (num, buf) => {
29
27
  buf[0] = 0xff
30
28
  var flipped = false
31
29
  num = num * -1
32
- for (var i = buf.length - 2; i > 0; i--) {
33
- var byte
34
- if (num === 0)
35
- byte = 0
36
- else {
37
- byte = num % 0x100
38
- num = Math.floor(num / 0x100)
39
- }
30
+ for (var i = buf.length; i > 1; i--) {
31
+ var byte = num & 0xff
32
+ num = Math.floor(num / 0x100)
40
33
  if (flipped)
41
- buf[i] = onesComp(byte)
34
+ buf[i-1] = onesComp(byte)
42
35
  else if (byte === 0)
43
- buf[i] = 0
36
+ buf[i-1] = 0
44
37
  else {
45
38
  flipped = true
46
- buf[i] = twosComp(byte)
39
+ buf[i-1] = twosComp(byte)
47
40
  }
48
41
  }
49
42
  }
@@ -51,8 +44,20 @@ const encodeNegative = (num, buf) => {
51
44
  const parse = exports.parse = (buf) => {
52
45
  var post = buf[buf.length - 1]
53
46
  var pre = buf[0]
54
- return pre === 0x80 ? pos(buf.slice(1, buf.length - 1))
55
- : twos(buf.slice(1, buf.length - 1))
47
+ var value;
48
+ if (pre === 0x80)
49
+ value = pos(buf.slice(1, buf.length))
50
+ else if (pre === 0xff)
51
+ value = twos(buf)
52
+ else
53
+ throw TypeError('invalid base256 encoding')
54
+
55
+ if (!Number.isSafeInteger(value))
56
+ // The number is so large that javascript cannot represent it with integer
57
+ // precision.
58
+ throw TypeError('parsed number outside of javascript safe integer range')
59
+
60
+ return value
56
61
  }
57
62
 
58
63
  const twos = (buf) => {
@@ -71,9 +76,9 @@ const twos = (buf) => {
71
76
  f = twosComp(byte)
72
77
  }
73
78
  if (f !== 0)
74
- sum += f * Math.pow(256, len - i - 1)
79
+ sum -= f * Math.pow(256, len - i - 1)
75
80
  }
76
- return sum * -1
81
+ return sum
77
82
  }
78
83
 
79
84
  const pos = (buf) => {
package/package.json CHANGED
@@ -2,13 +2,13 @@
2
2
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
3
3
  "name": "tar",
4
4
  "description": "tar for node",
5
- "version": "4.4.8",
5
+ "version": "4.4.9",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/npm/node-tar.git"
9
9
  },
10
10
  "scripts": {
11
- "test": "tap test/*.js --100 -J --coverage-report=text -c",
11
+ "test": "tap",
12
12
  "preversion": "npm test",
13
13
  "postversion": "npm publish",
14
14
  "postpublish": "git push origin --all; git push origin --tags",
@@ -18,19 +18,19 @@
18
18
  "dependencies": {
19
19
  "chownr": "^1.1.1",
20
20
  "fs-minipass": "^1.2.5",
21
- "minipass": "^2.3.4",
22
- "minizlib": "^1.1.1",
21
+ "minipass": "^2.3.5",
22
+ "minizlib": "^1.2.1",
23
23
  "mkdirp": "^0.5.0",
24
24
  "safe-buffer": "^5.1.2",
25
- "yallist": "^3.0.2"
25
+ "yallist": "^3.0.3"
26
26
  },
27
27
  "devDependencies": {
28
28
  "chmodr": "^1.2.0",
29
29
  "end-of-stream": "^1.4.1",
30
30
  "events-to-array": "^1.1.2",
31
31
  "mutate-fs": "^2.1.1",
32
- "rimraf": "^2.6.2",
33
- "tap": "^12.0.1",
32
+ "rimraf": "^2.6.3",
33
+ "tap": "^14.2.0",
34
34
  "tar-fs": "^1.16.3",
35
35
  "tar-stream": "^1.6.2"
36
36
  },
@@ -41,5 +41,9 @@
41
41
  "files": [
42
42
  "index.js",
43
43
  "lib/"
44
- ]
44
+ ],
45
+ "tap": {
46
+ "coverage-map": "map.js",
47
+ "check-coverage": true
48
+ }
45
49
  }