Skip to content

Commit 12ed73d

Browse files
committed
fix: do not use noAssert
Support for the `noAssert` argument was removed for Node.js 10.x and all input will be validated from now on nevertheless. This removes all `noAssert` entries and fixes a bug where the input was some times wrongly coerced to a negative value.
1 parent d941f97 commit 12ed73d

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

Diff for: lib/BufferUtil.fallback.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ module.exports.BufferUtil = {
1717
}
1818
},
1919
mask: function(source, mask, output, offset, length) {
20-
var maskNum = mask.readUInt32LE(0, true);
20+
var maskNum = mask.readUInt32LE(0);
2121
var i = 0;
2222
for (; i < length - 3; i += 4) {
23-
var num = maskNum ^ source.readUInt32LE(i, true);
23+
var num = maskNum ^ source.readUInt32LE(i);
2424
if (num < 0) { num = 4294967296 + num; }
25-
output.writeUInt32LE(num, offset + i, true);
25+
output.writeUInt32LE(num, offset + i);
2626
}
2727
switch (length % 4) {
2828
case 3: output[offset + i + 2] = source[i + 2] ^ mask[2];
@@ -32,13 +32,13 @@ module.exports.BufferUtil = {
3232
}
3333
},
3434
unmask: function(data, mask) {
35-
var maskNum = mask.readUInt32LE(0, true);
35+
var maskNum = mask.readUInt32LE(0);
3636
var length = data.length;
3737
var i = 0;
3838
for (; i < length - 3; i += 4) {
39-
var num = maskNum ^ data.readUInt32LE(i, true);
39+
var num = maskNum ^ data.readUInt32LE(i);
4040
if (num < 0) { num = 4294967296 + num; }
41-
data.writeUInt32LE(num, i, true);
41+
data.writeUInt32LE(num, i);
4242
}
4343
switch (length % 4) {
4444
case 3: data[i + 2] = data[i + 2] ^ mask[2];

Diff for: lib/WebSocketFrame.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ WebSocketFrame.prototype.addData = function(bufferList) {
8585
if (bufferList.length >= 2) {
8686
bufferList.joinInto(this.frameHeader, 2, 0, 2);
8787
bufferList.advance(2);
88-
this.length = this.frameHeader.readUInt16BE(2, true);
88+
this.length = this.frameHeader.readUInt16BE(2);
8989
this.parseState = WAITING_FOR_MASK_KEY;
9090
}
9191
}
@@ -94,10 +94,10 @@ WebSocketFrame.prototype.addData = function(bufferList) {
9494
bufferList.joinInto(this.frameHeader, 2, 0, 8);
9595
bufferList.advance(8);
9696
var lengthPair = [
97-
this.frameHeader.readUInt32BE(2, true),
98-
this.frameHeader.readUInt32BE(2+4, true)
97+
this.frameHeader.readUInt32BE(2),
98+
this.frameHeader.readUInt32BE(2+4)
9999
];
100-
100+
101101
if (lengthPair[0] !== 0) {
102102
this.protocolError = true;
103103
this.dropReason = 'Unsupported 64-bit length frame received';
@@ -149,7 +149,7 @@ WebSocketFrame.prototype.addData = function(bufferList) {
149149
this.invalidCloseFrameLength = true;
150150
}
151151
if (this.length >= 2) {
152-
this.closeStatus = this.binaryPayload.readUInt16BE(0, true);
152+
this.closeStatus = this.binaryPayload.readUInt16BE(0);
153153
this.binaryPayload = this.binaryPayload.slice(2);
154154
}
155155
}
@@ -204,7 +204,7 @@ WebSocketFrame.prototype.toBuffer = function(nullMask) {
204204
this.length += this.binaryPayload.length;
205205
}
206206
data = new Buffer(this.length);
207-
data.writeUInt16BE(this.closeStatus, 0, true);
207+
data.writeUInt16BE(this.closeStatus, 0);
208208
if (this.length > 2) {
209209
this.binaryPayload.copy(data, 2);
210210
}
@@ -242,20 +242,20 @@ WebSocketFrame.prototype.toBuffer = function(nullMask) {
242242

243243
if (this.length > 125 && this.length <= 0xFFFF) {
244244
// write 16-bit length
245-
output.writeUInt16BE(this.length, outputPos, true);
245+
output.writeUInt16BE(this.length, outputPos);
246246
outputPos += 2;
247247
}
248248
else if (this.length > 0xFFFF) {
249249
// write 64-bit length
250-
output.writeUInt32BE(0x00000000, outputPos, true);
251-
output.writeUInt32BE(this.length, outputPos + 4, true);
250+
output.writeUInt32BE(0x00000000, outputPos);
251+
output.writeUInt32BE(this.length, outputPos + 4);
252252
outputPos += 8;
253253
}
254254

255255
if (this.mask) {
256-
maskKey = nullMask ? 0 : (Math.random()*0xFFFFFFFF) | 0;
257-
this.maskBytes.writeUInt32BE(maskKey, 0, true);
258-
256+
maskKey = nullMask ? 0 : ((Math.random() * 0xFFFFFFFF) >>> 0);
257+
this.maskBytes.writeUInt32BE(maskKey, 0);
258+
259259
// write the mask key
260260
this.maskBytes.copy(output, outputPos);
261261
outputPos += 4;

0 commit comments

Comments
 (0)