Skip to content

Commit

Permalink
punycode: Test for integer overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 6, 2011
1 parent 2a848fa commit 8475e15
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var SKEW = 38;
var DAMP = 700; // initial bias scaler
var INITIAL_N = 128;
var INITIAL_BIAS = 72;
var MAX_INTEGER = Math.pow(2, 53);

function adapt_bias(delta, n_points, is_first) {
// scale back, then increase delta
Expand Down Expand Up @@ -151,7 +152,7 @@ function encode(input) {
for (var i = 0; i < len; ++i) {
var c = input[i];
if (c < n) {
if (++delta == 0) {
if (++delta == MAX_INTEGER) {
throw new Error('Delta overflow.');
}
}
Expand Down

0 comments on commit 8475e15

Please sign in to comment.