nomad / cola

🥤 A text CRDT for real-time collaborative editing
https://crates.io/crates/cola
MIT License
493 stars 12 forks source link

Decoding on a different arch should fail #1

Closed FlixCoder closed 1 year ago

FlixCoder commented 1 year ago

Just browsed through the code and saw something: You are using usize to encode and decode the length of a byte array. The number of bytes differs on different architectures, so decoding would fail on a 32 bit system if it was sent from a 64 bit system.

Why don't you just let bincode encode and decode the whole tuple of fields? It saves code and should be safer. You also need to think about security here, as it is supposed to be sent over the wire.

noib3 commented 1 year ago

Great catch! This should be fixed by https://github.com/nomad/cola/commit/9f780e67cb7d47c6d54c5c57cfa93d9d6e6d1360.

Why don't you just let bincode encode and decode the whole tuple of fields?

Because I'm planning to rewrite the encoding logic to produce much smaller binaries.