-
Notifications
You must be signed in to change notification settings - Fork 24
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
Clarify what should happen when a Reader
method returns an error result
#21
Comments
Still that doesn't seem very satisfying for |
The best solution for this is probably to change methods that take a Of course, that would be a highly disruptive change! |
I prototyped a refactoring of this library where every fallible I think instead we should investigate changing the semantics to be "whenever a method fails, the Reader is left in the same state as it previously was in." If we do that, we should also consider replacing the use of Those changes seem straightforward as far as the implementation of |
Definitely my expectation is that a user of
Reader
will stop using the reader after aReader
method fails. However, that expectation isn't documented anywhere.In discussing PR #20 with @oherrala (offline), the point was made that, based on the documentation in the
untrusted
module, noReader
methods must ever panic even if they are called after aReader
method returned an error.@oherrala Also suggested that we change things so that, once a Reader method returns an error, then all future calls to all other
Reader
methods would return an error. I brought up some concerns that this would add an extra check in each method that might hurt performance; we'd need to see how the optimizer copes with this. OTOHO @oherrala brought up the point that mostuntrusted
users probably care much more about safety than absolute performance. Still, it would be useful to try to minimize the performance impact based on the "performance is an aspect of security" mindset. One way to do it would be to set the Reader to the end of the input, and then only check the "previous error" bit when we detect we're at the end of the stream. The more problematic aspect of this idea is that there are methods likemark()
,peek()
, andskip_to_end()
that don't returns aResult
. It doesn't make much sense to have this sticky error bit only affect a subset of the methods of the Reader.Another alternative would be to have every
Reader
method consume the reader, i.e. takeself
instead of&mut self
as a parameter. Then every method would returnResult<(Reader, [current result type]), Error>
. We'd need to do some experimenting (e.g. rewritewebpki
) to validate such an API design.The text was updated successfully, but these errors were encountered: