pgriess / node-websocket-client

A Web Socket client for NodeJS
BSD 3-Clause "New" or "Revised" License
150 stars 68 forks source link

targetStart out of bounds [websocket.js:246] #1

Closed lgreenspan closed 14 years ago

lgreenspan commented 14 years ago

I get errors with websocket-client (as used in node-webworker) using node v0.1.100 on darwin. Using this test code http://gist.github.com/473964 and sending a request like

curl http://localhost:8000 --data '{"params": [1,2], "id": 1}'

I often (but not always) get

$ node master.js 
debugger listening on port 1025
targetStart out of bounds [/usr/local/node/lib/node/websocket-client/websocket.js:246]

Also connecting with d8 to the debug port, seems to more reliably cause this problem to appear. But this is only a correlation.

pgriess commented 14 years ago

I think what's going on is that we're not properly handling the case where 0xff is the first byte of the packet. In this case, after looping over bufs, we end up calling buf.copy() with the intent of copying 'i' (0) bytes. Though this should be a no-op, Buffer.copy() bounds-checks the source before looking at the length being copied.

pgriess commented 14 years ago

Fixed with 0.9.4.

pgriess commented 14 years ago

BTW, thanks for the great test-case. Very helpful in tracking down and fixing this.