Skip to content

Inexplicable "RangeError: Attempt to write outside buffer bounds" #7047

Closed
@feross

Description

@feross
  • Version: v6.2.0
  • Platform: Windows 10, possibly others
  • Subsystem: buffer

I've had multiple users report a RangeError: Attempt to write outside buffer bounds error that originates inside the Buffer constructor.

Here's some code that triggers it, according to the bug reports that I've received.

var buf = new Buffer(infoHash, 'hex')

Example stack traces:

Uncaught RangeError: Attempt to write outside buffer bounds
Buffer.write @ buffer.js:772
fromString @ buffer.js:238
Buffer.from @ buffer.js:131
Buffer @ buffer.js:112
Wire.handshake @ .../node_modules/bittorrent-protocol/index.js:192
RangeError: Attempt to write outside buffer bounds
    at Buffer.write (buffer.js:772:11)
    at fromString (buffer.js:238:26)
    at Function.Buffer.from (buffer.js:131:12)
    at new Buffer (buffer.js:112:17)
    at Function.encode.buffer (../webtorrent-cli/node_modules/bencode/lib/encode.js:61:17)

The call to buf.write that's crashing is in core, and it's here. Is the buffer pool offset incorrect somehow?

I don't understand how this could happen. Apologies for not having a reproducible test case. I haven't been able to reproduce it yet and I'm out of ideas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions