PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.95k stars 904 forks source link

Offset is not uint #146

Closed Dids closed 11 years ago

Dids commented 11 years ago

Getting this constantly, with the latest mineflayer and 1.4.7 server:

buffer.js:577 throw new RangeError('offset is not uint'); ^ RangeError: offset is not uint at checkOffset (buffer.js:577:11) at Buffer.readUInt8 (buffer.js:585:5)

andrewrk commented 11 years ago

I'll take a look. This is likely to be fixed this week as we upgrade to node v0.10 and minecraft protocol 1.5

llbit commented 11 years ago

I'm not good at JavaScript, but it seems that nibbleIndex is a floating point value when buffer.readUInt8 requires an unsigned integer value as parameter. I just edited mineflayer/lib/plugins/blocks.js and set nibbleIndex to zero (at lines 109 and 146). But to fix this properly I think you need to use Math.floor or some shit.

andrewrk commented 11 years ago

Yeah I noticed this too. I want to double check the math and the protocol to make sure we're calculating nibbleIndex correctly.

llbit commented 11 years ago

Is there a good reference page for the Minecraft multiplayer protocol?

andrewrk commented 11 years ago

wiki.vg/Protocol

rom1504 commented 11 years ago

adding Math.floor at line 109 and 146 of lib/plugins/blocks.js seems to solve this

andrewrk commented 11 years ago

I wonder if this will be solved by https://github.com/joyent/node/pull/5226

trevnorris commented 11 years ago

@superjoe30 no sorry. that PR fixes an assertion check that ensures you don't write beyond the buffer length. Right now it requires that input values are of type uint (coercion isn't done automatically at the moment). This can be done in one of the following ways: Math.floor(val), ~~val or val|0.

andrewrk commented 11 years ago

fixed by zuazo's pull request, released in 0.1.0