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

Ensure we're using compatible numeric types #27

Closed
jimmycuadra opened this issue Jun 15, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@jimmycuadra
Copy link
Member

commented Jun 15, 2019

Florian brought this up in #ruma:matrix:org:

While we are at breaking changes in ruma-events, I was recently made aware of this: https://matrix.org/docs/spec/appendices#canonical-json - all "integers" in the specification, e.g. powerlevels, can have the range [-(2**53)+1, (2**53)-1] unless noted to be positive only. From a quick check, it seems like ruma uses u64, i.e. [0, (2**64)-1], while we should use i64 and reject 2**53 - 2**64 as invalid.

Also, notes on integers to be positive only are much more sparse than I would have expected, might be an area where we have to go and fix the spec first instead of allowing negative integers everywhere.

the 2**53 seemed especially odd, until I realized that this is the f64 float limit, and remembered that javascript has no real integers but represents everything as floats.

at least for power level events, a power level of -1 is actually used regularily to mute people, so that would definitely be something that would break the current ruma. hopefully serde would just complain instead of having an integer underflow and giving the person MAX_INT powerlevel. ^^

@jplatte

This comment has been minimized.

Copy link
Contributor

commented Jun 16, 2019

I built a crate for this kind of integer: https://crates.io/crates/js_int
It shouldn't be hard to migrate the relevant ids to js_int::Int (or sometimes js_int::UInt). Updating issue label.

@jplatte jplatte added effort/easy and removed effort/normal labels Jun 16, 2019

jimmycuadra added a commit to ruma/ruma-client-api that referenced this issue Jun 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.