-
Notifications
You must be signed in to change notification settings - Fork 118
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
base64::decode_config_slice should not panic #192
Comments
|
I don't think the error has to be precise beyond "doesn't fit," but then there could be cases where an API-user is not looking for "should be exactly this many bytes" but instead "can be maximum this amount of bytes." I haven't looked in to that option and have never been in that situation myself. Adding the new enum variant just to the |
I wonder if |
Take a look at #207. I've released that as |
Fixed in 0.21.0. |
I think the panicking behavior of
base64::decode_config_slice
is a mistake, this is an error that an application receiving untrusted input should be able to deal with. The size of decoded data can be calculated from the base64 input, before runningbase64::decode_config_slice
; but I think this goes against separation of concerns. The API user shouldn't have to know about internals like that.There are situations where one wants to decode some untrusted base64 input, with a known maximum/absolute size, where the size is small enough that heap-allocation is unnecessary. A classic example of this would be a session ID.
Suggested implementation
I think
DecodeError
should have aBufferOverflow
variant, whichbase64::decode_config_slice
should return when it overflows a given mutable slice.I foresee two use-cases for this error:
Use-case number 2 should be strongly discouraged by the API docs, with a reference to
base64::decode
for decoding base64 of unknown length.Backwards-compatibility
The suggested implementation is not backwards compatible because it changes
DecodeError
, and is therefore unrealistic given the widespread use of this crate in the ecosystem.The implementation should therefore add a new function
basse64::decode_config_fixed_slice_bikeshed
with a new error-typeSliceDecodeErrorBikeshed
with variantsBufferOverflow
, andDecodeError(DecodeError)
while deprecatingbase64::decode_config_slice
.The text was updated successfully, but these errors were encountered: