diff --git a/lib/websocket.js b/lib/websocket.js index 973f00c..ab3178b 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -243,7 +243,17 @@ var WebSocket = function(url, proto) { assert.equal(mbOff, bufsBytes); - buf.copy(mb, mbOff, off, i); + // Don't call Buffer.copy() if we're coping 0 bytes. Rather + // than being a no-op, this will trigger a range violation on + // the destination. + if (i > 0) { + buf.copy(mb, mbOff, off, i); + } + + // We consumed all of the buffers that we'd been saving; clear + // things out + bufs = []; + bufsBytes = 0; } process.nextTick(function() {