Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

64-bit integers overflow #1

Closed
sjmulder opened this issue Feb 17, 2011 · 6 comments · Fixed by #9
Closed

64-bit integers overflow #1

sjmulder opened this issue Feb 17, 2011 · 6 comments · Fixed by #9

Comments

@sjmulder
Copy link
Owner

Values from TAG_Long tags may overflow if the value is negative or if it does not fit in 32 bits. This is a limitation of the library used for unpacking binary values.

@deathcap
Copy link
Contributor

Found this other NBT parsing library: https://github.com/maxogden/minecraft-nbt - it also has (about to fix) problems with TAG_Long, but the jdataview https://github.com/jdataview/jdataview library it uses supports 64-bit integers by splitting them into hi and lo fields (32-bit each, allows representing integers beyond 53-bits).

@sjmulder
Copy link
Owner Author

That looks like a good solution. You can submit a pull request if you feel like it, otherwise I’ll have a look soon.

sjmulder added a commit that referenced this issue Mar 16, 2014
@sjmulder
Copy link
Owner Author

Actually, maybe this should be configurable in some way. It really depends on the consumer what the desired output his. hi and lo fields are one good options, but other code may want to have a clamped value or even a string.

@deathcap
Copy link
Contributor

Hm, are there really situations where clamped values would be useful? Most 64-bit integers in NBT seem to be some kind of timestamp or identifier, where clamping could be problematic. Rounding would be problematic for identifiers, but possibly useful for timestamps.

Maybe valueOf could be implemented to return the approximate value (double, if coerced numerically), toString the precise decimal value as a string, and properties for the high and low halves.

@deathcap
Copy link
Contributor

@sjmulder Found this nifty module https://www.npmjs.org/package/node-int64 - looks like it solves all these problems, let me know what you think. Submitted PR to use this module in #9

@sjmulder
Copy link
Owner Author

That looks like a good solution, I’m surprised that the big values can be coerced to numbers. Thanks so much!

sjmulder added a commit that referenced this issue Mar 31, 2014
Use node-int64 for 64-bit long integers. Closes GH-1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants