Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: attempt to write outside buffer bounds #94

Closed
olalonde opened this issue Oct 31, 2015 · 16 comments
Closed

RangeError: attempt to write outside buffer bounds #94

olalonde opened this issue Oct 31, 2015 · 16 comments
Labels

Comments

@olalonde
Copy link

Getting this error when my client tries to connect to a webrtc peer:

...
  simple-peer [bf9f303] signal +4s
buffer.js:522
    throw new RangeError('attempt to write outside buffer bounds');
    ^

RangeError: attempt to write outside buffer bounds
    at Buffer.write (buffer.js:522:11)
    at fromString (buffer.js:115:26)
    at new Buffer (buffer.js:54:12)
    at Object.exports.hexToBinary (./node_modules/torrent-discovery/node_modules/bittorrent-tracker/lib/common.js:15:10)
    at Peer.<anonymous> (./node_modules/torrent-discovery/node_modules/bittorrent-tracker/lib/client/websocket-tracker.js:272:26)
    at Peer.g (events.js:260:16)
    at emitOne (events.js:77:13)
    at Peer.emit (events.js:169:7)
    at Peer.sendOffer (./node_modules/torrent-discovery/node_modules/bittorrent-tracker/node_modules/simple-peer/index.js:309:12)
    at Peer.g (events.js:260:16)
@olalonde
Copy link
Author

Interestingly, I added a console.log here:

exports.hexToBinary = function (str) {
  console.log(str.length);
  return new Buffer(str, 'hex').toString('binary')
}

and apparently, the string is just 40 characters...

@olalonde
Copy link
Author

Now getting a similar error here:

node_modules/torrent-discovery/node_modules/bittorrent-tracker/node_modules/ws/lib/Receiver.js:386
    default: srcBuffer.copy(dstBuffer, dstOffset, 0, length); break;
                       ^

RangeError: out of range index
    at RangeError (native)
    at fastCopy (/node_modules/torrent-discovery/node_modules/bittorrent-tracker/node_modules/ws/lib/Receiver.js:386:24)
    at Receiver.add (/node_modules/torrent-discovery/node_modules/bittorrent-tracker/node_modules/ws/lib/Receiver.js:86:3)
    at TLSSocket.realHandler (/node_modules/torrent-discovery/node_modules/bittorrent-tracker/node_modules/ws/lib/WebSocket.js:800:20)
    at emitOne (events.js:77:13)
    at TLSSocket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at TLSSocket.Readable.push (_stream_readable.js:110:10)
    at TLSWrap.onread (net.js:523:20)

Strange... Maybe this is due to the wrtc module not being compiled properly?

@olalonde
Copy link
Author

Well, those errors seem to go away with node 0.12.7.

@kumavis
Copy link

kumavis commented Dec 27, 2015

Getting a similar error from an entirely different code base - but I notice the ws and wrtc modules are in common

@feross
Copy link
Member

feross commented Dec 27, 2015

@olalonde Since your issue was fixed by upgrading to a newer version of node, I am going to close this issue now.

@kumavis It would be interesting to know what version of node you're using.

@feross feross closed this as completed Dec 27, 2015
@kumavis
Copy link

kumavis commented Dec 28, 2015

got the same error on v4.2.3 and v5.3.0

@feross
Copy link
Member

feross commented Dec 28, 2015

Sadly, I can't figure out what the issue might be without more information. Are you using a memory-constrained device like a Raspberry Pi? What do you think might be causing this?

@kumavis
Copy link

kumavis commented Dec 29, 2015

no, modern laptop - I don't think the actual issue matches the error message. I think wrtc somehow replaced the native Buffer ? I'm not really sure, and I'm not familiar with how native bindings work. I've avoided this issue by running in headless electron and using their wrtc classes. This is not a problem for me anymore, so I'm not going to pursue it. but thank you for following up.

@feross
Copy link
Member

feross commented Dec 29, 2015

Okay, thanks for letting me know. I think we're going to move away from wrtc in webtorrent-hybrid so hopefully this won't be an issue for anyone else in the future.

@kumavis
Copy link

kumavis commented Dec 30, 2015

@feross curious what you plan to replace it with. I was daydreaming about a module that would summon a headless electron process, setup an rpc over a stream, and create remote versions of the wrtc classes that mirrored their behaviour in the electron runtime. but seems like a large api surface area and would be a challenge to reproduce any synchronous behaviour.

@feross
Copy link
Member

feross commented Jan 1, 2016

@kumavis - that's actually something I've though of before! I think it actually might be possible too :)

However, I'm currently placing my hopes in https://github.com/nickdesaulniers/node-rtc-peer-connection by @nickdesaulniers. If that works out, it'll be a pure JavaScript WebRTC implementation, and all our problems will be solved 👍

@kumavis
Copy link

kumavis commented Jan 3, 2016

ah, nice! the javascript singularity approaches...

@feross
Copy link
Member

feross commented Jan 3, 2016

Indeed!

@paulkernfeld
Copy link

FWIW, I got this same error in an unrelated project on Node 5.5 because I tried to send a Buffer through a node-webrtc DataChannel. I don't know how that could have caused the original error, though, because it seems like simple-peer takes care of converting from Buffers.

For anyone who searches for this error message, you might instead want to check out node-webrtc/node-webrtc#103, "Allow sending node.js Buffer objects."

@olalonde
Copy link
Author

@paulkernfeld thanks for the link. At this point, I'm really hoping someone would take over node-webrtc and do a rewrite from scratch. If only I didn't suck at C++...

@feross
Copy link
Member

feross commented May 30, 2016

There's an issue about this on the main webtorrent repo: webtorrent/webtorrent#820 where we've made progress toward fixing this.

@feross feross added the bug label May 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants