Skip to content

Commit 25b25f6

Browse files
committed
prevent "value out of bounds error"
For webtorrent#72
1 parent ba7a58b commit 25b25f6

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/common-node.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
var querystring = require('querystring')
77

8+
var MAX_UINT = Math.pow(2, 32) - 1
9+
810
exports.IPV4_RE = /^[\d\.]+$/
911
exports.IPV6_RE = /^[\da-fA-F:]+$/
1012

@@ -25,6 +27,7 @@ exports.EVENT_NAMES = {
2527
}
2628

2729
function toUInt32 (n) {
30+
if (n > MAX_UINT) n = MAX_UINT
2831
var buf = new Buffer(4)
2932
buf.writeUInt32BE(n, 0)
3033
return buf

0 commit comments

Comments
 (0)