-
-
Notifications
You must be signed in to change notification settings - Fork 279
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
Please address suitability for untrusted inputs in docs #345
Comments
These are the answers to the questions outlined above:
|
Puts some prominent text into the `readme.md` regarding some use cases that are likely to be common, along with a few hopefully helpful pointers to avoid footguns. Closes bincode-org#345, closes bincode-org#216, addresses bincode-org#240, bincode-org#266.
…uts (#346) * Address questions regarding suitability for storage and untrusted inputs Puts some prominent text into the `readme.md` regarding some use cases that are likely to be common, along with a few hopefully helpful pointers to avoid footguns. Closes #345, closes #216, addresses #240, #266. * Fix typos in `readme.md` * Remove confusing sentence post 1.0, as requested
#240 sounds relevant for protecting against inputs claiming large field sizes, maliciously or due to corruption / version mismatch / cat on keyboard using netcat. |
A question that I have run into in multiple times on different projects is: How suitable is bincode for network communication?
Example scenario
A typical scenario is a networking application that sends messages between two participants (peer-to-peer or client server). By default, one can reach for JSON at this point, as the libraries are built against a spec and are safe dealing with hostile inputs (provided they are size-limited).
bincode
strikes me as something that (at least initially) was intended for trusted communication, possibly in-memory communication, potentially sacrificing support for input from untrusted sources for extra speed.This question seems to have been asked directly or in a roundabout way in multiple other issues: #216, #136, #221, #240, #255, #266.
Alternatives
There is a real hole in the Rust ecosystem that yearns to be filled with a compact binary format that can be used to send unversioned, untrusted data with serde support. Certainly protobuf, captain proto, flatbuffers exist, but they all tackle a grander scope and come with extra hoops to jump through - at least I just want to slap a
#[derive(Serialize)]
onto my struct and send it more efficiently than JSON across the aether.Of the available, mature alternatives, msgpack and bson are mentioned, but these are self-describing and thus "waste" space by serializing struct field names as well.
There are other non-established contenders listed in the serde docs, but many fail to address this issue in a precise manner in their docs as well.
The list
To judge suitability for using
bincode
for a specific project, at least the following questions need to be answered:Is the format stable/well-defined, i.e. does not change across minor versions. This is typically important when storing data using
bincode
long-term.Is the format invariant over differences in byte-order, that is will a big-endian machine produce the same output as a little-endian machine?
Is it space-efficient for binary data, i.e. will it be space efficient for large binary data?
Is it written with "hostile" data in mind? Rust's memory safety goes a long way of course, but some things like handling invalid inputs or not pre-allocating large amounts of memory when receiving a message are required, and typically a performance-security trade-off.
I may have missed some points, but these came to mind immediately.
It would be great if these could be answered in the docs - I will happily volunteer to write a note and add it to the
README.md
or core module docs, but each of these need an answer from someone who knows the actual source code well.Each question will actually need two answers, one addressing the status quo and another whether or not this is an accidental or intended property. Any project that relies on bincode certainly needs to know the guarantees it can expect from future versions.
Note that answering "don't know and won't ever guarantee it" on each of these is perfectly fine - I would just like to see it written down, as I find myself in discussions about this with my colleagues fairly often and having sent them to various GitHub issues, it seems that there is a real need for this information =).
If someone could just let me know informally about the state and goals, I will do my best to turn this into a PR updating the docs.
In the meantime, thanks for six years of work that already went into this crate :)
The text was updated successfully, but these errors were encountered: