Comparing version 5.0.0 to 5.0.1
@@ -15,3 +15,3 @@ module.exports = read | ||
do { | ||
if (counter >= l) { | ||
if (counter >= l || shift > 49) { | ||
read.bytes = 0 | ||
@@ -18,0 +18,0 @@ throw new RangeError('Could not decode varint') |
@@ -9,2 +9,6 @@ module.exports = encode | ||
function encode(num, out, offset) { | ||
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) { | ||
encode.bytes = 0 | ||
throw new RangeError('Could not encode varint') | ||
} | ||
out = out || [] | ||
@@ -11,0 +15,0 @@ offset = offset || 0 |
{ | ||
"name": "varint", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "protobuf-style varint bytes - use msb to create integer values of varying sizes", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
23
test.js
@@ -80,3 +80,2 @@ var varint = require('./index') | ||
bigs.push(Math.pow(2, i) - 1) | ||
bigs.push(Math.pow(2, i)) | ||
})(i) | ||
@@ -97,3 +96,3 @@ | ||
var MAX_INTD = Math.pow(2, 55) | ||
var MAX_INTD = Number.MAX_SAFE_INTEGER | ||
var MAX_INT = Math.pow(2, 31) | ||
@@ -115,3 +114,3 @@ | ||
for(var i = 0; i <= 53; i++) { | ||
var n = Math.pow(2, i) | ||
var n = Math.pow(2, i) - 1 | ||
assert.equal(encode(n).length, encodingLength(n)) | ||
@@ -140,4 +139,22 @@ } | ||
test('buffer too long', function (assert) { | ||
var buffer = Uint8Array.from( | ||
Array.from({length: 150}, function () { return 0xff }) | ||
.concat(Array.from({length: 1}, function () { return 0x1 })) | ||
) | ||
try { | ||
var val = decode(buffer) | ||
encode(val) | ||
assert.fail('expected an error received value instead: ' + val) | ||
} catch (err) { | ||
assert.equal(err.constructor, RangeError) | ||
assert.equal(decode.bytes, 0) | ||
} | ||
assert.end() | ||
}) | ||
function randint(range) { | ||
return Math.floor(Math.random() * range) | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9616
252