mcollina / msgpack5

A msgpack v5 implementation for node.js, with extension points / msgpack.org[Node]
MIT License
493 stars 76 forks source link

Maximum uint32 value (4294967295) is encoded as uint64 #36

Closed sgerace closed 9 years ago

sgerace commented 9 years ago

If you attempt to encode the value 4294967295, it encodes it as a uint64 instead of uint32.

Here is a minimal example:

msgpack.encode(4294967295) // = cf00000000ffffffff

When it should encode it as ceffffffff

Quickly glancing at the code, it looks like the issue is probably coming from https://github.com/mcollina/msgpack5/blob/master/lib/encoder.js#L96 where I believe it should read:

} else if (obj <= 0xffffffff) { // <-- missing "equal to"

(notice the equal to on the comparison).

I'd be happy to put together a pull request if it would help.

mcollina commented 9 years ago

@sgerace thanks for finding this out! :) It's really hard to get all edge cases correct.

Would you mind sending in a PR?

sgerace commented 9 years ago

@mcollina No problem, I'm actually writing a validator for MessagePack at the moment so I totally appreciate how many edge cases there are ;-)

The pull request is up (#37).