compact-encoding 3.1.0 → 3.2.0

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/index.js +7 -0
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1088,4 +1088,11 @@ function zigZagEncodeBigInt(n) {
1088
1088
  function validateUint(n) {
1089
1089
  if (n >= 0 === false /* Handles NaN as well */)
1090
1090
  throw new Error('uint must be positive')
1091
+ // Beyond this, Number arithmetic loses precision and silently corrupts the
1092
+ // encoding. The zig-zag int codecs route through here too, so this also
1093
+ // guards int values whose doubled magnitude exceeds the safe range.
1094
+ if (n > Number.MAX_SAFE_INTEGER)
1095
+ throw new Error(
1096
+ 'integer is greater than the maximum safe integer, use biguint/bigint'
1097
+ )
1091
1098
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compact-encoding",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "A series of compact encoding schemes for building small and fast parsers and serializers",
5
5
  "main": "index.js",
6
6
  "files": [