-
Notifications
You must be signed in to change notification settings - Fork 31
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
Encode trait methods should be fallible #675
Comments
I'm not necessarily opposed to this, but when considering a panic vs. an error we should ask: is the error recoverable? If you have some object whose length prefix is |
Arguably we've fixed this particular problem by draft-05, but the same kind of idea midht come up in other cases. |
+1 to making this fallible. I would go further and suggest that we make this library operate on streams of data rather than byte buffers/
I disagree -- this error could be because the user of the library (e.g. Janus or Daphne) attempted to cram too much data into a structure; this is not a programmer-error in the sense of being always a bug. And since the maximum amount of data that can fit into a structure is opaque to the user of the library, the user can't easily avoid this bug either. Also, even if we encounter this error, we would want to propagate the error to the caller (via an error return value) to allow the caller to terminate/retry/etc that one request, rather than panicking which might take out the entire process. |
(another way to think of this: as long as we panic on input-too-large, a relatively-untrusted Client can cause us to panic at any time by sending too much data in a field of a |
@divergentdave do you think we can pick this up in the next release? I'd love to see this happen. |
I think that makes sense, it'll be the most disruptive breaking change we've done in a while, but I think it's worth it. I split off a separate issue for switching from monolithic buffers to streams as a possible follow-on. |
Yup, I am all for this change, despite the churn for Janus & other users of the library. I think it closes what would otherwise be an almost-unavoidable panic (from the POV of users of the library) which might be caused by untrusted user input. (and fwiw, I'm fine separating the "operate on streams rather than byte buffers" suggestion out to its own issue -- while I still think it's a good idea, it's less critical.) |
I think we should make
Encode::encode()
fallible in the next breaking change release. Currently the various functions that encode vectors panic if their contents exceed the limits of the length prefix, but this ought to instead be an error for the caller to propagate or handle.The text was updated successfully, but these errors were encountered: