Navigation Menu

Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
Some fixes to lo-byte parser
Browse files Browse the repository at this point in the history
- The lo-byte parser would incorrectly call buf.copy() with an offset at
  the end of the target buffer and a length of 0. Though this is
  theoretically a no-op, Buffer.copy() is doing bounds-checking on the
  source before taking the length into account.
- Clear bufs[] and bufBytes when consuming partial buffer.
  • Loading branch information
pgriess committed Jul 13, 2010
1 parent 3452978 commit 14584bf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/websocket.js
Expand Up @@ -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() {
Expand Down

0 comments on commit 14584bf

Please sign in to comment.